Adjust Figures#
Figure Size, Background Color, DPI, etc.#
Built-in parameters of matplotlib.pyplot.figure could be passed alone with Waffle as FigureClass and PyWaffle parameters. Some of them are commonly used to adjust figure, like figsize, dpi, facecolor, tight_layout, etc. Check matplotlib.pyplot.figure for the details.
In the following example, we change the background color of figure by passing color value to facecolor.
fig = plt.figure(
FigureClass=Waffle,
rows=5,
values=[30, 16, 4],
colors=["#232066", "#983D3D", "#DCB732"],
facecolor='#DDDDDD' # facecolor is a parameter of matplotlib.pyplot.figure
)
Note
Charts with many blocks. In a raster format such as PNG, block edges land on fractional pixel positions and the rasterizer rounds them to whole pixels, so the gaps between columns alternate by one pixel. PyWaffle’s own geometry is exactly uniform - the difference appears only when the chart is rasterized. It is invisible at ordinary sizes, but with a thousand blocks a block may be only ~15 pixels wide and a 1 pixel difference becomes noticeable.
To avoid it, save to a vector format, where coordinates stay fractional and the grid is exact:
fig.savefig("chart.svg") # or .pdf
Raising dpi also helps, since the 1 pixel error stays constant while the blocks grow. See
issue #2 for measurements.
Plot Location#
Use parameter plot_anchor to change the location of plot in the figure.
fig = plt.figure(
FigureClass=Waffle,
rows=5,
values=[30, 16, 4],
plot_anchor='S'
)
fig.set_facecolor('#DDDDDD')
Parameter tight controls whether tight_layout in matplotlib is called when drawing.
Tight Layout#
By default, PyWaffle sets the figure with tight layout. Thus, when showing the plot, the following warning might pop up:
UserWarning: This figure includes Axes that are not compatible with tight_layout, so its results might be incorrect
It is usually not an issue when saving the plot to a file, so it could ignored. If you still want to remove the moving, you can either suppress warnings through Python’s warnings module, or set PyWaffle parameter tight to False.