python - Seaborn 无法覆盖 Matplotlib 的 rcParams ['grid.linewidth' ]

标签 python matplotlib seaborn

当我尝试使用 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”,这里都是输出。

grid

最佳答案

您可以为此使用 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()

3d grid with linewidth

set_styleset_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/

相关文章:

Python:拆分字符串行

python - 使用 python 请求的 SSLError

python - 结合彩色散点图和单独的线图

python - 在标绘线上打印字符串(模拟等高线图标签)

python - pandas 对于 value_counts() 中不存在的类别填写 0

python - Matplotlib 和 Seaborn : Legend too long for line style

Python加入整数列表

python - 无法使用 python 查找元音计数

python - 如何叠加 Pandas 图、matplotlib 图和轴

python - 使用 Seaborn 条形图分离(并保留)重复的分类数据?