Repository: ydataai/ydata-profiling

Issue:
Pie Chart is not being displayed in pandas profile report
I am trying to have variables of categorical type with less than 10 unique values show as a pie chart. I see an option in the configuration yaml. However, when I generate the report I still see it as a bar chart. 




Discussion:
Hi @bedangSen, the pie chart is added to the report, but doesn't replace the frequency table as you might have expected.

For instance, see "Pclass" in: https://pandas-profiling.github.io/pandas-profiling/examples/master/titanic/titanic_report.html
(click "Toggle details" to see the pie chart)
Ahhh I gotcha! Apologies for the confusion, this is great! Quick question though - is there a way to change the color of the pie chart to the primary colors selected in the config file? (Example attached below)

![image](https://user-images.githubusercontent.com/35425072/92403794-44f17880-f143-11ea-8e21-6a2a62dd6491.png)

@bedangSen Not yet, however the change would be simple. You're welcome to contribute.

You can find the relevant code here: https://github.com/pandas-profiling/pandas-profiling/blob/master/src/pandas_profiling/visualisation/plot.py#L283

Resolving patch:
diff --git a/src/pandas_profiling/config.py b/src/pandas_profiling/config.py
--- a/src/pandas_profiling/config.py
+++ b/src/pandas_profiling/config.py
@@ -133,6 +133,11 @@ class Pie(BaseModel):
     # display a pie chart if the number of distinct values is smaller or equal (set to 0 to disable)
     max_unique: int = 10
 
+    # Colors shoud be a list of matplotlib recognised strings:
+    # --> https://matplotlib.org/stable/tutorials/colors/colors.html
+    # --> matplotlib defaults are used by default
+    colors: Optional[List[str]] = None
+
 
 class Plot(BaseModel):
     missing: MissingPlot = MissingPlot()
diff --git a/src/pandas_profiling/visualisation/plot.py b/src/pandas_profiling/visualisation/plot.py
--- a/src/pandas_profiling/visualisation/plot.py
+++ b/src/pandas_profiling/visualisation/plot.py
@@ -302,6 +302,19 @@ def scatter_pairwise(
 def pie_plot(
     config: Settings, data: pd.Series, legend_kws: Optional[dict] = None
 ) -> str:
+    """Generate pie plot showing proportions of categorical and boolean
+    variables. Modify colors by setting 'config.plot.pie.colors' to a
+    list of valid matplotib colors.
+    https://matplotlib.org/stable/tutorials/colors/colors.html
+
+    Args:
+        config (Settings): a config
+        data (pd.Series): the categories and their frequency
+        legend_kws (Optional[dict], optional): Defaults to None.
+
+    Returns:
+        str: pie plot encoded in text
+    """
     if legend_kws is None:
         legend_kws = {}
 
@@ -313,7 +326,12 @@ def my_autopct(pct: float) -> str:
 
         return my_autopct
 
-    wedges, _, _ = plt.pie(data, autopct=make_autopct(data), textprops={"color": "w"})
+    wedges, _, _ = plt.pie(
+        data,
+        autopct=make_autopct(data),
+        textprops={"color": "w"},
+        colors=config.plot.pie.colors,
+    )
     plt.legend(wedges, data.index.values, **legend_kws)
 
     return plot_360_n0sc0pe(config)


Test patch:
diff --git a/tests/unit/test_visualizations.py b/tests/unit/test_visualizations.py
new file mode 100644
--- /dev/null
+++ b/tests/unit/test_visualizations.py
@@ -0,0 +1,26 @@
+"""
+Test for the visualization functionality  
+"""
+import pandas as pd
+
+from pandas_profiling import ProfileReport
+from pandas_profiling.utils.cache import cache_file
+
+test_data = pd.DataFrame([1, 2, 3])
+
+matplotlib_colors = {"gold": "#ffd700", "b": "#0000ff", "#FF796C": "#ff796c"}
+
+def test_report_with_custom_pie_chart_colors():
+    profile = ProfileReport(df=test_data,
+        progress_bar=False,
+        samples=None,
+        correlations=None,
+        missing_diagrams=None,
+        duplicates=None,
+        interactions=None,
+    )
+    profile.config.plot.pie.colors = list(matplotlib_colors.keys())
+    
+    html_report = profile.to_html()
+    for c, hex_code in matplotlib_colors.items():
+        assert "fill: {}".format(hex_code) in html_report, f"Missing color code of {c}"