I want to have control over the face color of (sub)plots when I use matplotlib.
For example, if I run,
tips = sns.load_dataset("tips")
f, ax = plt.subplots(subplot_kw=dict(facecolor=".9"))
sns.scatterplot(data=tips, x="total_bill", y="tip")
I get this,
where the default white face color is changed to gray. Running though,
tips = sns.load_dataset("tips")
rows, cols = 1, 1
f, axs = plt.subplots( rows, cols, subplot_kw=dict(facecolor=".9"))
plt.subplot( rows, cols, 1)
sns.scatterplot(data=tips, x="total_bill", y="tip")
gives,
Setting explicitly the face color at each subplot command resolves it, i.e.,
tips = sns.load_dataset("tips")
rows, cols = 1, 1
f, axs = plt.subplots( rows, cols)
plt.subplot( rows, cols, 1, facecolor=".9")
sns.scatterplot(data=tips, x="total_bill", y="tip")
However, when I use plt.box( False)
or
ax = plt.subplot( rows, cols, 1, facecolor = ".9")
ax.set_frame_on( False)
or
plt.subplot( rows, cols, 1, facecolor = ".9", frame_on = False)
the problem returns. It appears that, custom face color with no frame cannot be met as "configurations".
From the documentation of frame_on
property, "Set whether the axes rectangle patch is drawn.", https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.set_frame_on.html#matplotlib.axes.Axes.set_frame_on. Hence, it looks like that matplotlib
adds a patch to change the face color.
Is it then possible to change the edge color of this patch? I don't want to have this "thick" border line of the frame. Is adding my own patch the only alternative?
EDIT
When I try this,
tips = sns.load_dataset("tips")
rows, cols = 2, 1
f, axs = plt.subplots( rows, cols, figsize = ( 10, 10), subplot_kw = dict( facecolor = ".9"))
plt.subplot( rows, cols, 1)
sns.scatterplot(data=tips, x="total_bill", y="tip", ax = axs[ 0])
axs[ 0].grid( color = 'w', linewidth = 1)
[ axs[ 0].spines[ s].set_visible( False) for s in axs[ 0].spines.keys()]
I get this,
The problem is that I am calling plt.subplot()
that creates a new axis overriding the one at location ( rows, cols, 1)
. Deleting this line solves the problem.
Thanks.