Here is a donut plot with 3 groups and several subgroups for each. You can set the position of the 2 circle levels using the radius and width options. Then, the idea is to attribute a color palette for each group. Note that the code for this graphic is far from optimal. It would be great to create a more general function. Do not hesitate to leave a comment if you have a better way to do it!
# Libraries import matplotlib.pyplot as plt # Make data: I have 3 groups and 7 subgroups group_names=['groupA', 'groupB', 'groupC'] group_size=[12,11,30] subgroup_names=['A.1', 'A.2', 'A.3', 'B.1', 'B.2', 'C.1', 'C.2', 'C.3', 'C.4', 'C.5'] subgroup_size=[4,3,5,6,5,10,5,5,4,6] # Create colors a, b, c=[plt.cm.Blues, plt.cm.Reds, plt.cm.Greens] # First Ring (outside) fig, ax = plt.subplots() ax.axis('equal') mypie, _ = ax.pie(group_size, radius=1.3, labels=group_names, colors=[a(0.6), b(0.6), c(0.6)] ) plt.setp( mypie, width=0.3, edgecolor='white') # Second Ring (Inside) mypie2, _ = ax.pie(subgroup_size, radius=1.3-0.3, labels=subgroup_names, labeldistance=0.7, colors=[a(0.5), a(0.4), a(0.3), b(0.5), b(0.4), c(0.6), c(0.5), c(0.4), c(0.3), c(0.2)]) plt.setp( mypie2, width=0.4, edgecolor='white') plt.margins(0,0) # show it plt.show()
Hi,
First of all thanks for the web, it’s amazing and helps me a lot!
I just want to ask you if it’s possible to change the order of the increase. I mean, you have the subgroups growing from left to rigth. If I do just a group of incremental numbers, these also grownth from left to rigth, I would need to invert that. And it would be nice if I could choose the starting point (A1 in your example).
Also, I would like to know if it’s possible to remove the internal lines that separate the subgroups, I just want the color increment or decrement but without that lines.
Thanks so much
Hi,
I made a more general function for this that takes advantage of the `groupby()` operation in Pandas to handle the groupings. I also added a sequential palette generator so that it handles as many groups as needed.
The first page that comes up when you click launch binder at https://github.com/fomightez/donut_plots_with_subgroups demonstrates the full-featured script that includes a full-featured function. The second page breaks things down into what is needed to parallel the code above.
Repo: https://github.com/fomightez/donut_plots_with_subgroups
active launch: https://mybinder.org/v2/gh/fomightez/donut_plots_with_subgroups/master?filepath=index.ipynb
Static view of basics page: https://nbviewer.jupyter.org/github/fomightez/donut_plots_with_subgroups/blob/master/demo_basics_from_df.ipynb
Static view of script demo: https://nbviewer.jupyter.org/github/fomightez/donut_plots_with_subgroups/blob/master/index.ipynb
Hi,
I made a more general function for this that takes advantage of the `groupby()` operation in Pandas to handle the groupings. I also added a sequential palette generator so that it handles as many groups as needed.
The first page that comes up when you click launch binder at https://github.com/fomightez/donut_plots_with_subgroups demonstrates the full-featured script that includes a full-featured function. The second page breaks things down into what is needed to parallel the code above.
Repo: https://github.com/fomightez/donut_plots_with_subgroups
active launch: https://mybinder.org/v2/gh/fomightez/donut_plots_with_subgroups/master?filepath=index.ipynb
Static view of basics page: https://nbviewer.jupyter.org/github/fomightez/donut_plots_with_subgroups/blob/master/demo_basics_from_df.ipynb
Static view of script demo: https://nbviewer.jupyter.org/github/fomightez/donut_plots_with_subgroups/blob/master/index.ipynb