matplotlib柱形图与盒图

import pandas as ps

import matplotlib.pyplot as plt

reviews = pd.read_csv(r"E:\PyCharm\fandango_score_comparison.csv")

cols = ["FILM", "RT_user_norm", "Metacritic_user_nom", "IMDB_norm", "Fandango_Ratingv

norm_reviews = reviews[cols]

fig, ax = plt.subplots()

ax.hist(norm_reviews["Fandango_Ratingvalue")                                     #查看不同区间的个数(蓝)

ax.hist(norm_reviews["Fandango_Ratingvalue", bins=20)                      #同时分成20个容器

ax.hist(norm_reviews["Fandango_Ratingvalue", range=(4,5) bins=20)  #同时选择区间4到5

如下图:

fig = plt.figure(figsize=(10,5))

ax1 = fig.add_subplot(2,2,1)

ax2 = fig.add_sbplot(2,2,4)

ax1.hist(norm_reviews["Fandango_Ratingvalue"], range(0,5), bins=20)

ax2.hist(norm_reviews["Fandango_Ratingvalue"], range(0.5), bins=20)

ax2.set_ylim(10,50)               #设置y轴的范围

如图:

盒图如下(4分图):

fig, ax = plt.subplots()

ax.boxplot(norm_reviews["RT_user_norm"])                      #设置4分图

ax.set_xticklabels(norm_reviews["RT_user_norm"])          #把x轴名字改为RE_user_norm

ax.set_ylim(0,5)                                                                  #设置高度范围

plt.show()

如图:

多盒图在同一张图中显示

num_cols = ["RT_user_norm", "Metacritic_user_nom","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()

如下图;

猜你喜欢

转载自blog.csdn.net/qq_39112101/article/details/85055464