简体   繁体   English

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

[英]Seaborn cannot override Matplotlib's rcParams['grid.linewidth']

When I am trying to set the grid of a 3D plot using seaborn, such as当我尝试使用 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()

The parameter "grid.linewidth" does not have any affect on the grid linewidth, however, if I add参数"grid.linewidth"对网格线宽没有任何影响,但是,如果我添加

  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?任何人都可以解释如何将其纳入 seaborn 功能或我做错了什么? It does not matter where I place the rcParam inside the function.我将 rcParam 放在函数内的哪个位置并不重要。

Here is the output regardless of whether I put "2" or "200".无论我输入“2”还是“200”,这里都是输出。

网格

You can use set_context for this.您可以为此使用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 网格

set_style and set_context have these differing explanations for their rc dict, below. set_styleset_context对它们的 rc dict 有这些不同的解释,如下。

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM