簡體   English   中英

Python matplotlib.pyplot 餅圖:如何去掉左邊的標簽?

[英]Python matplotlib.pyplot pie charts: How to remove the label on the left side?

我使用 pyplot 繪制餅圖。

import pylab
import pandas as pd
test = pd.Series(['male', 'male', 'male', 'male', 'female'], name="Sex")
test = test.astype("category")
groups = test.groupby([test]).agg(len)
groups.plot(kind='pie', shadow=True)
pylab.show()

結果:

在此處輸入圖片說明

但是,我無法移除左側的標簽(圖中標記為紅色)。 我已經試過了

plt.axes().set_xlabel('')

plt.axes().set_ylabel('')

但這沒有用。

你可以只設置ylabel通過調用pylab.ylabel

pylab.ylabel('')

或者

pylab.axes().set_ylabel('')

在您的示例中, plt.axes().set_ylabel('')將不起作用,因為您的代碼中沒有import matplotlib.pyplot as plt ,因此plt不存在。

或者, groups.plot命令返回Axes實例,因此您可以使用它來設置ylabel

ax=groups.plot(kind='pie', shadow=True)
ax.set_ylabel('')

或者:

groups.plot(kind='pie', shadow=True , ylabel='' )

使用 plot 函數時添加 label="" 參數

groups.plot(kind='pie', shadow=True,label="")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM