Python-Matplotlib(4) 直方图与四分图
2017-08-13 11:16
453 查看
import pandas as pd import matplotlib.pyplot as plt reviews = pd.read_csv('fandango_scores.csv') cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue'] norm_reviews = reviews[cols] print(norm_reviews[:5])
fandango_distribution = norm_reviews['Fandango_Ratingvalue'].value_counts() fandango_distribution = fandango_distribution.sort_index() imdb_distribution = norm_reviews['IMDB_norm'].value_counts() imdb_distribution = imdb_distribution.sort_index() print(fandango_distribution) print(imdb_distribution)
2.7 2
2.8 2
2.9 5
3.0 4
3.1 3
3.2 5
3.3 4
3.4 9
3.5 9
3.6 8
3.7 9
3.8 5
3.9 12
4.0 7
4.1 16
4.2 12
4.3 11
4.4 7
4.5 9
4.6 4
4.8 3
Name: Fandango_Ratingvalue, dtype: int64
2.00 1
2.10 1
2.15 1
2.20 1
2.30 2
2.45 2
2.50 1
2.55 1
2.60 2
2.70 4
2.75 5
2.80 2
2.85 1
2.90 1
2.95 3
3.00 2
3.05 4
3.10 1
3.15 9
3.20 6
3.25 4
3.30 9
3.35 7
3.40 1
3.45 7
3.50 4
3.55 7
3.60 10
3.65 5
3.70 8
3.75 6
3.80 3
3.85 4
3.90 9
3.95 2
4.00 1
4.05 1
4.10 4
4.15 1
4.20 2
4.30 1
Name: IMDB_norm, dtype: int64
fig, ax = plt.subplots() ax.hist(norm_reviews['Fandango_Ratingvalue']) #ax.hist(norm_reviews['Fandango_Ratingvalue'],bins=20) #ax.hist(norm_reviews['Fandango_Ratingvalue'], range=(4, 5),bins=20) plt.show()
fig = plt.figure(figsize=(5,20)) ax1 = fig.add_subplot(4,1,1) ax2 = fig.add_subplot(4,1,2) ax3 = fig.add_subplot(4,1,3) ax4 = fig.add_subplot(4,1,4) ax1.hist(norm_reviews['Fandango_Ratingvalue'], bins=20, range=(0, 5)) ax1.set_title('Distribution of Fandango Ratings') ax1.set_ylim(0, 50) ax2.hist(norm_reviews['RT_user_norm'], 20, range=(0, 5)) ax2.set_title('Distribution of Rotten Tomatoes Ratings') ax2.set_ylim(0, 50) ax3.hist(norm_reviews['Metacritic_user_nom'], 20, range=(0, 5)) ax3.set_title('Distribution of Metacritic Ratings') ax3.set_ylim(0, 50) ax4.hist(norm_reviews['IMDB_norm'], 20, range=(0, 5)) ax4.set_title('Distribution of IMDB Ratings') ax4.set_ylim(0, 50) plt.show()
fig, ax = plt.subplots() ax.boxplot(norm_reviews['RT_user_norm']) ax.set_xticklabels(['Rotten Tomatoes']) ax.set_ylim(0, 5) plt.show()
num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue'] fig, ax = plt.subplots() ax.boxplot(norm_reviews[num_cols].values) ax.set_xticklabels(num_cols, rotation=90) ax.set_ylim(0,5) plt.show()
相关文章推荐
- Python基于matplotlib绘制栈式直方图的方法示例
- python matplotlib之 hist直方图
- python matplotlib 画直方图报错
- python数据分析——matplotlib生成折线图,散点图和直方图
- 【Python-matplotlib】画直方图(hist)
- Python-matplotlib 画直方图hist
- Python进阶(三十八)-数据可视化の利用matplotlib 进行折线图,直方图和饼图的绘制
- Python数据可视化:Matplotlib 直方图、箱线图、条形图、热图、折线图、散点图。。。
- Python使用matplotlib模块绘制图像并设置标题与坐标轴等信息示例
- python包matplotlib基础入门
- Python matplotlib生成图片背景透明
- Matplotlib Toolkits:python高级绘图库seaborn
- Python matplotlib生成图片背景透明
- python之matplotlib学习绘制动态更新图实例代码
- python matplotlib 入门系列一:基本用法
- (Windows)Python用压缩包方法安装Numpy和MatplotLib
- python matplotlib 绘制双Y轴曲线图
- Python使用matplotlib实现在坐标系中画一个矩形的方法
- Python 安装matplotlib,six,dateutil,pyparsing 完整过程
- python——数据可视化:matplotlib,seaborn,pandas