当我尝试使用 seaborn 设置 3D 绘图的网格时,例如
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()
参数"grid.linewidth"
对网格线宽没有任何影响,但是,如果我添加
plt.rcParams['grid.linewidth'] = 2
在设置图形之前,我可以更改网格厚度。谁能解释如何将其合并到 seaborn 函数中或我做错了什么?我将 rcParam 放在函数中的什么位置并不重要。
无论我输入“2”还是“200”,这里都是输出。
最佳答案
您可以为此使用 set_context
。
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
和 set_context
对它们的 rc dict 有这些不同的解释,如下所示。
源代码定义了parameters under each category, here的列表并且在 this previous question 中也有更详细的解释。 .
<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.
关于python - Seaborn 无法覆盖 Matplotlib 的 rcParams ['grid.linewidth' ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69618816/