导入numpy库、pandas库和Matplotlib库
import pandas as pd
import numpy
import matplotlib.pyplot as plt
导入文件
reviews = pd.read_csv("fandango_score_comparison.csv")
柱形图
生成一个柱形图:
#bist图(柱形图)
fig, ax = plt.subplots()
#ax.hist(norm_reviews['IMDB'])
#ax.hist(norm_reviews['IMDB'], bins = 20)
#range:设置图像显示的区间,bins:将数据等分为bins份
ax.hist(norm_reviews['Fandango_Stars'], range = (3, 5), bins = 20)
plt.show()
图像:
盒图
生成一个盒图:
#boxplot(盒形图)
fig, ax = plt.subplots()
ax.boxplot(norm_reviews['Fandango_Stars'])
ax.set_xticklabels(['Fandango'])
ax.set_ylim(2.5, 5.5)
plt.show()
图像:
在一张图表里生成多个盒图
#绘制多个boxplot
num_cols = ['Metacritic_User', 'IMDB', 'Fandango_Stars', 'Fandango_Ratingvalue', 'RT_norm']
fig, ax = plt.subplots()
ax.boxplot(norm_reviews[num_cols].values)
ax.set_xticklabels(num_cols, rotation = 90)
plt.show()
图像:
附:
可视化库Matplotlib-折线统计图
可视化库Matplotlib-子图
可视化库Matplotlib-条形图与散点图