Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable white frames on matplotlib figure/ Disable transparent frames

I'm running ipython notebook on a dark theme. When I build a chart on this, the chart is white, but the frame is transparent (hence dark), hiding the ticks which are also dark. Is there a way to make the frame not transparent/ white?

The ticks are barely visible due to the black background.

The ticks are barely visible due to black background.

How do I solve this? Thanks!

Edit: This is not about changing the colors of axis, ticks/labels, I'm thinking of adding a white background frame, not changing the colors of ticks - it'll be ugly if I just change the color of the ticks because the figure is white

like image 443
Rocky Li Avatar asked Sep 17 '18 15:09

Rocky Li


People also ask

What does rcParams do in Python?

Changing the Defaults: rcParams Each time Matplotlib loads, it defines a runtime configuration (rc) containing the default styles for every plot element you create. This configuration can be adjusted at any time using the plt.

What is BBOX in Matplotlib?

BboxTransformTo is a transformation that linearly transforms points from the unit bounding box to a given Bbox. In your case, the transform itself is based upon a TransformedBBox which again has a Bbox upon which it is based and a transform - for this nested instance an Affine2D transform.

What does PLT axis off do?

To hide the grid, use plt. To hide the axes, use plt.axis('off') To activate the labels' legend, use the legend() method. To display the figure, use the show() method.

How do I make Axis invisible in Matplotlib?

How to hide axis in matplotlib figure? The matplotlib. pyplot. axis('off') command us used to hide the axis(both x-axis & y-axis) in the matplotlib figure.


1 Answers

The figure shown in jupyter with the %matplotlib inline backend (which is often the default) is created via saving it through savefig to a png that is then displayed. savefig has an argument facecolor which sets the color of the figure background. This can be set to white, e.g. fig.savefig("name.png", facecolor="w").

The options for saving can be adapted in the jupyter configuration. To achieve a white background one can set

%config InlineBackend.print_figure_kwargs={'facecolor' : "w"}

in a cell prior to showing the plot.

If that is to be used for every notebook, it can also be added to the ipython configuration file

c = get_config()
c.InlineBackend.print_figure_kwargs={'facecolor' : "w"}
like image 130
ImportanceOfBeingErnest Avatar answered Sep 30 '22 14:09

ImportanceOfBeingErnest