I'm trying to save a plot with the labels area (the area where you print the xlabel, ylabel and title) transparent and the main plot (the area where you plot the data) not transparent.
I'm using the transparent command in savefig:
plt.savefig("name",tranparent=True)
The problem is that this makes all the figure transparent.
In the documentation says this about the transparent argument:
transparent : bool
If True, the axes patches will all be transparent; the figure patch will also be transparent unless facecolor and/or edgecolor are specified via kwargs. This is useful, for example, for displaying a plot on top of a colored background on a web page. The transparency of these patches will be restored to their original values upon exit of this function.
So I tried changing the facecolor
and edgecolor
arguments, but I can't find a combination that gives the plot that I want.
Help.
If you want to make something completely transparent, simply set the alpha value of the corresponding color to 0. For plt. savefig , there is also a "lazy" option by setting the rc-parameter savefig. transparent to True , which sets the alpha of all facecolors to 0%.
Use legend() method to avoid overlapping of labels and autopct. To display the figure, use show() method.
Often you may use subplots to display multiple plots alongside each other in Matplotlib. Unfortunately, these subplots tend to overlap each other by default. The easiest way to resolve this issue is by using the Matplotlib tight_layout() function.
There is a bug in the newest version of matplotlib. I'm not sure if this applies to here, because you do not state which version you are using.
The workaround would be to use a transparent facecolor and leave the other arguments at their defaults.
fig.savefig("fname", facecolor=(1,1,1,0))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With