1.在一个图表中包含两个数据系列
import csv
from datetime import datetime
from matplotlib import pyplot as plt
filename='sitka_weather_07-2018_simple.csv'
with open(filename) as f:
reader=csv.reader(f)
header_row=next(reader)
dates, highs, lows=[], [], []
for row in reader:
current_date=datetime.strptime(row[2],"%Y-%m-%d")
dates.append(current_date)
high=int(row[5])
highs.append(high)
low=int(row[6])
lows.append(low)
fig=plt.figure(dpi=128,figsize=(20,12))
plt.plot(dates,highs, c='red')
plt.plot(dates,lows,c='blue')
plt.title("PRCT-precipitation降水量",fontsize=24)
plt.xlabel('',fontsize=16)
fig.autofmt_xdate()
plt.ylabel("PRCT-precipitation降水量",fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=16)
plt.show()
结果是
2.
以下是给两个数据集之间的区域着色。
2.1 alpha表示透明度,其中1为完全不透明,0为完全透明。
2.2 plt.fill_between(dates,highs,lows,facecolor=‘blue’,alpha=0.1)用于填充两条折线之间区域。
import csv
from datetime import datetime
from matplotlib import pyplot as plt
filename='sitka_weather_07-2018_simple.csv'
with open(filename) as f:
reader=csv.reader(f)
header_row=next(reader)
dates, highs, lows=[], [], []
for row in reader:
current_date=datetime.strptime(row[2],"%Y-%m-%d")
dates.append(current_date)
high=int(row[5])
highs.append(high)
low=int(row[6])
lows.append(low)
fig=plt.figure(dpi=128,figsize=(20,12))
plt.plot(dates,highs, c='red', alpha=0.5)
plt.plot(dates,lows,c='blue', alpha=0.5)
plt.fill_between(dates, highs, lows, facecolor='blue',alpha=0.1)
plt.title("PRCT-precipitation降水量",fontsize=24)
plt.xlabel('',fontsize=16)
fig.autofmt_xdate()
plt.ylabel("PRCT-precipitation降水量",fontsize=16)
plt.tick_params(axis='both',which='major',labelsize=16)
plt.show()
结果是