import pandas as pd
import numpy as np
import glob
import datetime
from matplotlib import pyplot as plt
import copy
import re
import time
from pylab import *
import matplotlib.dates as mdate
import matplotlib.patches as patches
pop ={'weight': 'normal', 'size': 15}
df = pd.read_csv(r'.通量.csv')
print(df)
fig = plt.figure(figsize=(16,8))
plt.rcParams['font.sans-serif'] = 'Microsoft YaHei'
ax = fig.add_subplot(111)
ax2 = ax.twinx()
ax.plot(df.year,df.ssd,color = 'b',label = '年均输沙量')
ax.scatter(df.year,df.ssd)
ax2.plot(df.year,df.runoff,color = 'r', dashes=[6, 2],label = '年均流量')
ax2.scatter(df.year,df.runoff,color= 'r')
ax.set_ylabel("年输沙量 (百万吨)",fontdict=pop)
ax2.set_ylabel("年均流量 (立方米/秒)",fontdict=pop)
plt.xlim(1950,2020)
ax.set_xlabel('年份',fontsize=20)
fig.legend(loc=1, bbox_to_anchor=(1,1), bbox_transform=ax.transAxes) # 合并图例
plt.savefig(r'.1.png')
plt.show()