我正在嘗試使用 matplotlib 和 seaborn 為軸背景顏色和圖形背景顏色使用不同的顏色。我得到了下面的圖表。
sns.set(rc = {'axes.facecolor': 'yellow', 'figure.facecolor': 'red'})
plt.figure(figsize = (6,6))
sns.scatterplot(x = x, y = y, data = df)
plt.show()

但我不想要那些 whitegrid 線,想要在軸下打勾并呼叫sns.set_style('ticks').
sns.set(rc = {'axes.facecolor': 'yellow', 'figure.facecolor': 'red'})
plt.figure(figsize = (6,6))
sns.set_style('ticks')
sns.scatterplot(x = x, y = y, data = df)
plt.show()

我得到了我想要的刻度,但是軸背景顏色沒有像我設定的那樣出現'axes.facecolor': 'yellow'。為什么會這樣?如何設定刻度并獲得沒有網格線的指定背景顏色?
另外,如何調整圖形背景顏色的寬度,使上圖中的紅色條在所有 4 個邊上的寬度相等?
uj5u.com熱心網友回復:
是樣式定義的axes.facecolor一部分,因此如果您想使用 seaborn 樣式但還需要覆寫它的一些引數,您需要同時執行這兩項操作:
sns.set_theme(style='ticks', rc={'axes.facecolor': 'yellow', 'figure.facecolor': 'red'})
plt.figure(figsize=(6,6))
sns.scatterplot(x=x, y=y, data=df)
plt.show()
請注意,我切換sns.set到sns.set_theme; 它們是別名,做同樣的事情,但是set_theme是首選介面,sns.set將來可能會被棄用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/529727.html
