當我嘗試使用 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”,這里都是輸出。
![Seaborn 無法覆寫 Matplotlib 的 rcParams['grid.linewidth']](https://img.uj5u.com/2021/10/19/76aa964ba88c4972beb61d59c6b1d8f0.png)
uj5u.com熱心網友回復:
您可以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()
![Seaborn 無法覆寫 Matplotlib 的 rcParams['grid.linewidth']](https://img.uj5u.com/2021/10/19/d97952629eae437381056b6398719a5a.png)
set_style并set_context在下面對他們的 rc dict 有這些不同的解釋。
這個答案更詳細地涵蓋了差異。
<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.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/324250.html
標籤:Python matplotlib 海生
