seaborn rc parameters for set_context and set_style

Viewed 6341

In the tutorial for setting up the aesthetics of your plots, there are a few different methods:

  1. set_style
  2. set_context
  3. axes_style

Each one of these accepts an rc keyword parameter dictionary. In each individual API page for the above three functions, it says:

rcdict, optional: Parameter mappings to override the values in the preset seaborn style dictionaries. This only updates parameters that are considered part of the style definition.

Back in the tutorial page, under axes_style it goes on to say exactly how you can see what parameters are available for the rc dictionary for this one function:

If you want to see what parameters are included, you can just call the function with no arguments, which will return the current settings:

However, using this on the other functions always returns None. So, for example, I am using the following mix of matplotlib and seaborn to set parameters:

mpl.rcParams['figure.figsize'] = [16,10]
viz_dict = {
    'axes.titlesize':18,
    'axes.labelsize':16,
} 
sns.set_context("notebook", rc=viz_dict)
sns.set_style("whitegrid")

I also noticed that putting my dictionary in the set_style method does nothing, while, at least for those parameters, it only works in set_context. This means that they each have mutually exclusively characteristics that can be edited. However, this is not outlined anywhere in the docs.

I want to know which one of these three functions will accept a parameter for figsize. I'd also be curious to see what else they accept that might help me fine-tune things. My goal is to exclusively use the seaborn interface as often as possible. I don't need the fine tune control of things matplotlib provides, and often find it awkward anyway.

1 Answers

It would appear that the answer is 'none of the above'. The valid keys for set_style and set_context are listed here:

_style_keys = [
    "axes.facecolor", "axes.edgecolor",
    "axes.grid", "axes.axisbelow", "axes.labelcolor",

    "figure.facecolor", "grid.color", 
    "grid.linestyle", "text.color",

    "xtick.color", "ytick.color",
    "xtick.direction", "ytick.direction", 
    "lines.solid_capstyle",

    "patch.edgecolor", "patch.force_edgecolor",

    "image.cmap", "font.family", "font.sans-serif",

    "xtick.bottom", "xtick.top",
    "ytick.left", "ytick.right",

    "axes.spines.left", "axes.spines.bottom",
    "axes.spines.right", "axes.spines.top",]

_context_keys = [
    "font.size", "axes.labelsize",
    "axes.titlesize", "xtick.labelsize",
    "ytick.labelsize", "legend.fontsize",

    "axes.linewidth", "grid.linewidth",
    "lines.linewidth", "lines.markersize",
    "patch.linewidth",

    "xtick.major.width", "ytick.major.width",
    "xtick.minor.width", "ytick.minor.width",

    "xtick.major.size", "ytick.major.size",
    "xtick.minor.size", "ytick.minor.size",]

Also note that set_style is just a convenience function which calls axes_style.

So you will have to use matplotlib.rcParams, although if the typical rcParams['figure.figsize'] = [16,10] syntax is not amenable you could of course create your own style.

Related