[英]Move Y-Axis Zero Point to the Center in Seaborn Matplotlib
我有一個圖表也有負值,這意味着我的條形圖位於 x 軸脊柱上方和下方。 我想將 Y 軸的 0 點移到中間。 我怎樣才能做到這一點?
plt.style.use('dark_background')
self.figure = plt.figure(figsize=(12, 1), dpi=120)
# plt.subplots_adjust(bottom=0.15)
self.canvas = FigureCanvas(self.figure)
self.figure.clear()
self.figure.add_subplot(111)
df = pd.DataFrame({'Year': years, 'Receivables': receivable, 'Sales': orders, 'Payments': payment})
for i in df.index:
word = df.loc[i, "Receivables"]
y = df.loc[i, "Receivables"]
plt.annotate(f'{word:,.0f}', (i, y), rotation=90, ha="left", va="bottom", fontsize=8)
p = sns.barplot(x='Year', y='Receivables', data=df)
p.axes.set_title("Receivables".format(year), fontsize=11)
sns.lineplot(data=orders, sort=False, legend=True, label='Sales')
sns.lineplot(data=payment, sort=False, legend=True, label='Payments')
我通過反復試驗找到了答案。
因此,與其手動重新定位它。 我更改了軸 Y 軸限制。 因為我認為 matplotlib 在我的圖表中設置的限制太高:
p = sns.barplot(x='Year', y='Receivables', data=df)
p.axes.set_title("Receivables".format(year), fontsize=11)
sns.lineplot(data=orders, sort=False, legend=True, label='Sales')
sns.lineplot(data=payment, sort=False, legend=True, label='Payments')
p.set_xticklabels(years, fontsize=8, rotation=90, verticalalignment='top')
添加了這個: p.axes.set_ylim(-8000000, 8000000)
以便繪制時值不會太小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.