import matplotlib.pyplot as plt
from 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 bar
num_cols =['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']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.5)
plt.show()
同理,創(chuàng)建完簡(jiǎn)單的條形圖之后要對(duì)其進(jìn)行美化處理:
num_cols =['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
bar_heights = norm_reviews.ix[0, num_cols].values
bar_positions = arange(5)+0.75
tick_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 (2015)')
plt.show()
當(dāng)然,還有橫向條形圖:
import matplotlib.pyplot as plt
from numpy import arange
num_cols =['RT_user_norm','Metacritic_user_nom','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']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.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 (2015)')
plt.show()