标签:1.7 att tick nbsp 等等 语句 st表 atp ons
折线图的绘制
import pandas as pd
unrate = pd.read_csv(‘unrate.csv‘) unrate[‘DATE‘] = pd.to_datetime(unrate[‘DATE‘]) # 转换成datetime的格式
import matplotlib.pyplot as plt
first_twelve = unrate[0:12]
plt.plot(first_twelve[‘DATE‘],first_twelve[‘VALUE‘]) # x轴,y轴
plt.xticks(rotation=45) # x轴的标签倾斜45度
plt.xlabel(‘Month‘)
plt.ylabel(‘Unemployment Rate‘)
plt.title(‘Monthly Unemployment Trends,1948‘)
plt.show()
在一张图中绘制2条折线
unrate[‘MONTH‘] = unrate[‘DATE‘].dt.month
unrate[‘MONTH‘] = unrate[‘DATE‘].dt.month
fig = plt.figure(figsize=(6,3))
plt.plot(unrate[0:12][‘MONTH‘],unrate[0:12][‘VALUE‘],c=‘red‘) # 折线颜色为红色
plt.plot(unrate[12:24][‘MONTH‘],unrate[12:24][‘VALUE‘],c=‘blue‘)
plot.show()
在一张图中绘制n条折线
fig = plt.figure(figsize=(10,6))
color = [‘red‘,‘blue‘,‘green‘,‘orange‘,‘black‘]
for i in range(5):
start_index = i*12
end_index = (i+1)*12
subset = unrate[start_index:end_index]
label = str(1948 + i)
plt.plot(subset[‘MONTH‘],subset[‘VALUE‘],c=color[i],label=label) # label:在图中显示的标签内容
plt.legend(loc=‘best‘) # 只要设置了这条语句,label才能显示出来,best表示的是放置label的位置,还可以有left,right,upper left等等
plt.show()
子图操作
import matplotlib.pyplot as plt
import numpy as np fig = plt.figure(figsize=(6,3)) # 设置绘图区间,figsize为绘图的大小,指宽度和高度 ax1 = fig.add_subplot(2,2,1)
ax1.plot(np.random.randint(1,5,5),np.arange(5)) ax2 = fig.add_subplot(2,2,2) ax3 = fig.add_subplot(2,2,4) plt.show()
柱形图(横竖柱形图)
import matplotlib.pyplot as plt from numpy import arange num_cols = [‘RT‘,‘Meta‘,"IMDB‘,Fandango‘] bar_heights = norm_review.ix[0,num_cols].values bar_positions = arange(5) + 0.75 # [0.75,1.75,2.75,3.75,4.75]表示与原点的距离
tick_positions = range(1,6) fig,ax = plt.subplots()
ax.bar(bar_positions,bar_heights,0.3) # 0.3表示柱子的宽度,ax.barh表示是横着画柱形图
ax.set_xticks(tick_positions)
ax.set_xticklabels(num_cols,rotation=45) # x轴的label倾斜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()
散点图
fig,ax = plt.subplots() ax.scatter(norm_reviews[‘Fandango‘],norm_reviews[‘RT‘])
ax.set_xlabel(‘Fandango‘)
ax.set_ylabel(‘Rotten Tomatoes‘)
plt.show()
标签:1.7 att tick nbsp 等等 语句 st表 atp ons
原文地址:http://www.cnblogs.com/panjie123pakho/p/7863073.html