Savefig outputs blank image
If plt.savefig('output.png')
results in a blank output, save the plot prior to executing plt.show()
. Plot elements rendered post-display (plt.show()
) are not stored, which leads to a blank image.
Jumping between figures: plt.gcf() to the rescue
In scenarios that require dealing with multiple figures, plt.gcf()
is your lifeline. It captures the existing figure and eliminates the potential confusion:
Subplots — more is merrier
Adjust subplot parameters with plt.subplot()
to prevent your plots from feeling claustrophobic, because nobody likes cramped spaces, right?
Dots per inch: What's in a dpi?
Aesthetics matter; and so does a higher dpi
(dots per inch). Increase the dpi
to bedazzle your audience with high-quality images:
Coloring outside the lines
Ensure all your visual doodads, like legends and axis labels, are included and visible before preserving them for posterity. Remember, it's not complete without some captions and legends:
No imshow or sns discrimination
Functions like imshow
have feelings too!
For Seaborn enthusiasts, consider using the ax
argument:
The hide and seek game with data
Before applauding yourself for a job well done, ensure your data isn't in stealth mode. Verify it's visible:
Filenames are identifiers too
Prevent the possible overwriting of plots by celebrating uniqueness. Use Time Stamps, because they sure won't repeat:
Was this article helpful?