首页 > 解决方案 > 我试图让 X 轴用字符串而不是数字:字符串是(“电影”,“电视节目”),Y 轴用数字填充,直到 8000

问题描述

正如您在标题中所读到的那样,这就是我遇到的问题,不仅如此,我还需要将其绘制为带有两个单独条形的条形图,一个用于电影,一个用于电视节目,这是因为我想显示有多少电影与电视节目之间的差异。

substr = 'Movie'
substr1 = 'TV Show'

print('This are how many movies are in this dataframe:',netflix_df.type.str.count(substr).sum())
print('This are how many TV Show are in this dataframe:',netflix_df.type.str.count(substr1).sum())

输出:

This are how many movies are in this dataframe: 5377
This are how many TV Show are in this dataframe: 2410

我遇到问题的部分

x_ticks_labels = ['Movie','TV Shows']
plt.title('Movies/TV Shows')
plt.hist([netflix_df.type.str.count(substr).sum(),netflix_df.type.str.count(substr1).sum()],
        bins = np.arange(x_ticks_labels),
        stacked = True);
plt.legend(['TV Show','Movies']); 

标签: pythonmatplotlibbar-chart

解决方案


推荐阅读