[英]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.