Best way to display Seaborn/Matplotlib plots with a dark iPython Notebook profile
Solution 1
You can customize the seaborn style, and it tries to make it relatively easy to do so.
If you want to see each of the parameters that is considered part of the "style" definition, just call sns.axes_style()
with no arguments, and it will return the current settings. As of 0.3.1 and for the default style ("darkgrid"), that looks like this:
{'axes.axisbelow': True,
'axes.edgecolor': 'white',
'axes.facecolor': '#EAEAF2',
'axes.grid': True,
'axes.labelcolor': '.15',
'axes.linewidth': 0,
'font.family': 'Arial',
'grid.color': 'white',
'grid.linestyle': '-',
'image.cmap': 'Greys',
'legend.frameon': False,
'legend.numpoints': 1,
'legend.scatterpoints': 1,
'lines.solid_capstyle': 'round',
'pdf.fonttype': 42,
'text.color': '.15',
'xtick.color': '.15',
'xtick.direction': 'out',
'xtick.major.size': 0,
'xtick.minor.size': 0,
'ytick.color': '.15',
'ytick.direction': 'out',
'ytick.major.size': 0,
'ytick.minor.size': 0}
A good heuristic is that you probably only need the parameters with "color"
in the name, so you can filter it:
{k: v for k, v in sns.axes_style().items() if "color" in k}
returns
{'axes.edgecolor': 'white',
'axes.facecolor': '#EAEAF2',
'axes.labelcolor': '.15',
'grid.color': 'white',
'text.color': '.15',
'xtick.color': '.15',
'ytick.color': '.15'}
You can then pass a custom dictionary with values for these parameters into sns.set_style()
:
custom_style = {'axes.labelcolor': 'white',
'xtick.color': 'white',
'ytick.color': 'white'}
sns.set_style("darkgrid", rc=custom_style)
Solution 2
sns.set_style("darkgrid")
Will make the background white so that you can see the text.
Solution 3
Why not simply
plt.style.use("dark_background")
Solution 4
I find that adding this
plt.figure(facecolor='w')
each time I plot takes care of the axes background.
Related videos on Youtube
user11994
Updated on May 06, 2022Comments
-
user11994 13 days
I use the fantastic Seaborn library for some summary stats in IPython Notebook. I recently switched over to a dark color theme for my notebooks and am trying to figure out the best seeings for Seaborn with a dark background. I am using the
darkgrid
style but the legends are still being printed in black which makes them impossible to read. Here is an example:What is the best way to fix my styles of use of Seaborn to make the legends appear on white?
UPDATE: I just noticed that the same problem exists with my Matplotlib graphs.. so my question is more general. What styles do you use to allow for white on dark plots so the legends are readable?
-
Ander Biguri almost 7 yearsYeah, but: can you set it as default? Or do you need to paste this piece of code in every notebook?