# 电影评分
import pandas as pd
import matplotlib.pyplot as plt
reviews = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/fandango_scores.csv")
cols = ['FILM','RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews = reviews[cols]
print(norm_reviews[:1])
FILM ... Fandango_Stars
0 Avengers: Age of Ultron (2015) ... 5.0
import pandas as pd
import matplotlib.pyplot as plt
from numpy import arange
reviews = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/fandango_scores.csv")
num_cols = ['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews = reviews[num_cols]
# The Axes.bar() method has 2 required parameters,left and height
# We use the left parameter to specify the x coordinates of the left sides of the bar
# We use the height parameter to specify the height of each bar
bar_heights = norm_reviews.ix[0,num_cols].values
print(bar_heights)
bar_positions = arange(5) + 0.75
print(bar_positions)
fig,ax = plt.subplots()
ax.bar(bar_positions,bar_heights,0.3) #0.3 代表当前每个柱子的宽度
plt.show()
[4.3 3.55 3.9 4.5 5. ]
[0.75 1.75 2.75 3.75 4.75]
import pandas as pd
import matplotlib.pyplot as plt
from numpy import arange
reviews = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/fandango_scores.csv")
num_cols = ['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews = reviews[num_cols]
# The Axes.bar() method has 2 required parameters,left and height
# We use the left parameter to specify the x coordinates of the left sides of the bar
# We use the height parameter to specify the height of each bar
bar_heights = norm_reviews.ix[0,num_cols].values
#print(bar_heights)
bar_positions = arange(5) + 0.75
#print(bar_positions)
tick_positions = range(1,6)
fig,ax = plt.subplots()
ax.bar(bar_positions,bar_heights,0.3)
ax.set_xticks(tick_positions)
ax.set_xticklabels(num_cols,rotation = 45)
ax.set_xlabel('Rating Score')
ax.set_ylabel('Average Rating')
ax.set_title('Average User Rating For Avengers: Age of Ultron (2015)')
plt.show()
import pandas as pd
import matplotlib.pyplot as plt
from numpy import arange
reviews = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/fandango_scores.csv")
num_cols = ['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews = reviews[num_cols]
bar_widths = norm_reviews.ix[0,num_cols].values
bar_positions = arange(5) + 0.75
tick_positions = range(1,6)
fig,ax = plt.subplots()
ax.barh(bar_positions,bar_widths,0.3)
ax.set_yticks(tick_positions)
ax.set_yticklabels(num_cols)
ax.set_ylabel('Rating Score')
ax.set_xlabel('Average Rating')
ax.set_title('Average User Rating For Avengers: Age of Ultron (2015)')
plt.show()
import pandas as pd
import matplotlib.pyplot as plt
from numpy import arange
reviews = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/fandango_scores.csv")
num_cols = ['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews = reviews[num_cols]
fig,ax = plt.subplots()
ax.scatter(norm_reviews['Fandango_Ratingvalue'],norm_reviews['RT_user_norm'])
ax.set_xlabel('Fandango')
ax.set_ylabel('Rotten Tomatoes')
plt.show()
import pandas as pd
import matplotlib.pyplot as plt
from numpy import arange
reviews = pd.read_csv("C:/Users/Amber/Documents/唐宇迪-机器学习课程资料/Python库代码(4个)/3-可视化库matpltlib/fandango_scores.csv")
num_cols = ['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews = reviews[num_cols]
fig = plt.figure(figsize=(5,10))
ax1 = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
ax1.scatter(norm_reviews['Fandango_Ratingvalue'],norm_reviews['RT_user_norm'])
ax1.set_xlabel('Fandango')
ax1.set_ylabel('Rotten Tomatoes')
ax2.scatter(norm_reviews['RT_user_norm'],norm_reviews['Fandango_Ratingvalue'])
ax2.set_xlabel('Rotten Tomatoes')
ax2.set_ylabel('Fandango')
plt.show()
矩阵:DataFrame格式
DataFrame中的行/列为Series,即DataFrame是由Series组成的
来源:CSDN
作者:史努B
链接:https://blog.csdn.net/f2157120/article/details/104114045