1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > matplotlib matplotlib绘制条形图 散点图(三)

matplotlib matplotlib绘制条形图 散点图(三)

时间:2022-02-17 21:23:49

相关推荐

matplotlib matplotlib绘制条形图 散点图(三)

matplotlib matplotlib绘制条形图、散点图(三)

#%%import pandas as pdreviews = pd.read_csv('fandango_scores.csv')cols = ['FILM', 'RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']norm_reviews = reviews[cols]norm_reviews[:10]#%%import matplotlib.pyplot as pltfrom numpy import arange#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 barnum_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']bar_heights = norm_reviews.loc[0, num_cols].valuesprint(bar_heights) # 打印y轴的值bar_positions = arange(5) + 0.75print(bar_positions)# 打印x轴的值fig, ax = plt.subplots()# ax:为得到的画布;fig用于设置参数ax.bar(bar_positions, bar_heights, 0.5) # 参数设置:0.5表示当前柱的宽度plt.show()#%% md## 绘制条形图#%%#By default, matplotlib sets the x-axis tick labels to the integer values the bars #spanned on the x-axis (from 0 to 6). We only need tick labels on the x-axis where the bars are positioned. #We can use Axes.set_xticks() to change the positions of the ticks to [1, 2, 3, 4, 5]:num_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']bar_heights = norm_reviews.loc[0, num_cols].valuesbar_positions = arange(5) + 0.75tick_positions = range(1,6)fig, ax = plt.subplots()ax.bar(bar_positions, bar_heights, 0.5)ax.set_xticks(tick_positions)ax.set_xticklabels(num_cols, rotation=45)ax.set_xlabel('Rating Source')ax.set_ylabel('Average Rating')ax.set_title('Average User Rating For Avengers: Age of Ultron ()')plt.show()#%%import matplotlib.pyplot as pltfrom numpy import arangenum_cols = ['RT_user_norm', 'Metacritic_user_nom', 'IMDB_norm', 'Fandango_Ratingvalue', 'Fandango_Stars']bar_widths = norm_reviews.loc[0, num_cols].valuesbar_positions = arange(5) + 0.75tick_positions = range(1,6)fig, ax = plt.subplots()ax.barh(bar_positions, bar_widths, 0.5) # 表示绘制水平的条形图ax.set_yticks(tick_positions)ax.set_yticklabels(num_cols)ax.set_ylabel('Rating Source')ax.set_xlabel('Average Rating')ax.set_title('Average User Rating For Avengers: Age of Ultron ()')plt.show()#%% md## 绘制散点图#%%#Let's look at a plot that can help us visualize many points.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()#%%#Switching Axesfig = 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()#%%#%%···

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。