When I am trying to set the grid of a 3D plot using seaborn, such as
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("white",{"grid.color": "0.2", "grid.linestyle": "-","grid.linewidth": "2"})
fig = plt.figure(figsize=(12,8))
ax = plt.axes(projection='3d')
plt.show()
The parameter "grid.linewidth"
does not have any affect on the grid linewidth, however, if I add
plt.rcParams['grid.linewidth'] = 2
before I set the figure, then I am able to change the grid thickness. Would anyone be able to explain how to incorporate that into the seaborn function or what I'm doing wrong? It does not matter where I place the rcParam inside the function.
Here is the output regardless of whether I put "2" or "200".
CodePudding user response:
You can use set_context
for this.
import matplotlib.pyplot as plt
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D
sns.set_style("white", {'grid.color': "0.2", "grid.linestyle": "--"})
sns.set_context("notebook", rc={"grid.linewidth": 3})
fig = plt.figure(figsize=(12,8))
ax = plt.axes(projection='3d')
plt.show()
set_style
and set_context
have these differing explanations for their rc dict, below.
This answer covers the difference in further detail.
<set_style>
rc : dict, 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.
<set_context>
rc : dict, optional
Parameter mappings to override the values in the preset seaborn
context dictionaries. This only updates parameters that are
considered part of the context definition.