【发布时间】:2019-10-01 21:57:51
【问题描述】:
import matplotlib.pyplot as plt
import pandas as pd
from PIL import Image
import numpy as np
#code here
df = pd.DataFrame(items) #items is a list of dictionaries
counts =df.groupby('Merchant')['Merchant 1'].count().sort_values(ascending=False)counts2 =df.groupby('Merchant 2')['Seller'].count().sort_values(ascending=False)
total = counts.add(counts2, fill_value=0)
plt.ylabel('Number')
plt.xlabel("Merchant")
plt.title('Merchants Overview',color='b')
total.plot(kind='bar')
plt.xticks(rotation='horizontal')
plt.savefig("ex")
提供正确的“条”,但文本在 x 轴上重叠
另一个快速的问题,如何将条形从高到低排序。
我检查了这个Pandas plot hide some x-axis labels,还有x axis label in plot overlaps 这是我的第一个问题,请多多关照。
【问题讨论】:
-
正确的方法是使用
rot=参数:total.plot(kind='bar', rot=...)如复制所示。