15

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

4
  • @Yuca I don't think so, it's not changing the colors of axis, ticks/labels, I'm thinking of adding a white background frame so I don't have to change them - it'll be ugly if I just change the color of the ticks because the figure is white.
    – Rocky Li
    Sep 17, 2018 at 17:32
  • Possible duplicate of stackoverflow.com/q/14088687/9754169
    – Yuca
    Sep 17, 2018 at 17:36
  • sorry for the wrong link, this should be the correct one :) (you need to modify the figure's patch property)
    – Yuca
    Sep 17, 2018 at 17:37
  • 1
    @Yuca Thanks this solves it!
    – Rocky Li
    Sep 18, 2018 at 18:49

2 Answers 2

15

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"}
1
  • Thank you! I had tried setting matplotlibrc, it does not work. It turns out to be an IPython problem! Apr 29, 2020 at 12:11
0

To have a transparent frame just add the following line after loading matplotlib:

import matplotlib.pyplot as plt
plt.rcParams['axes.facecolor'] = 'none'

This did the trick for me!

1
  • 1
    The question was about how to make the frame "not transparent"
    – sappjw
    Nov 10, 2021 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.