3

So I found the pywaffle library which is apt for the visualization I need. But I need it to be a part of subplot in combination with a seaborn/matplotlib chart. But I can't find any way to actually make the plot.

An example of the plot layout I'm trying to make.

desired layout

Pywaffle provides a Figure constructor class Waffle, which could be passed to matplotlib.pyplot.figure and generates a matplotlib Figure object. Example code below:

fig = plt.figure(
    FigureClass=Waffle, 
    rows=5, 
    columns=10, 
    values=[48, 46, 6],
    figsize=(5, 3)
)
plt.show()
tdy
  • 36,675
  • 19
  • 86
  • 83
Tarique
  • 463
  • 3
  • 16
  • 1
    I think the only way is to use the waffle function to draw waffle graphs as described in [this answer](https://stackoverflow.com/questions/41400136/how-to-do-waffle-charts-in-python-square-piechart), and matplotlib or seaborn to draw the rest. – r-beginners Aug 27 '21 at 08:23
  • it looks like pywaffle just commandeers the entire `figure` (kind of like seaborn's figure-level plots), so i don't _think_ there's a way to use pywaffle with subplots – tdy Aug 27 '21 at 09:10
  • 1
    Thanks. I found a workaround that isn't particularly elegant but works for this particular layout on an inline-enabled jupyter notebook. I added a subplot to the fig using ax1 = fig.add_subplot(1, 2, 2) and made the 2nd plot using ax1. For the plot at the bottom, I just wrote a whole new graph after the plt.show() for the fig above in the same cell. Seems like we can't use sub_plots but this solution worked for me. – Tarique Aug 27 '21 at 09:19
  • I'm interested in solving your problem. Would you like to self-answer? – r-beginners Aug 29 '21 at 01:51

1 Answers1

0

PyWaffle 1.0.1 now supports accepting existed axis https://pywaffle.readthedocs.io/en/latest/examples/figure_and_axis_manipulation.html, this should allow you creating your figure first then plot waffle chart in one of subplots.

Guangyang Li
  • 2,711
  • 1
  • 24
  • 27