冲淤厚度作图

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
import matplotlib.ticker as ticker
df = pd.read_csv(r'.\冲淤量.csv')
print(df)
pop ={'weight': 'normal', 'size': 15}
fig = plt.figure(figsize=(16,8))
plt.rcParams['font.sans-serif'] = 'simsun'

ax1 = fig.add_subplot(111)

ax2 = ax1.twinx()
ax1.bar(df.year,df.volume_1,color = 'gray')
tick_spacing = 50
# tick_spacing = 5
# ax1.set_ylim(-120,200)
ax2.plot(df.year,df.av_vl,color = 'black')
# ax2.set_ylim(-1.3,2.3)
ax2.scatter(df.year,df.av_vl,color = 'black')
ax1.set_ylabel('年冲淤量',fontdict=pop)
ax2.set_ylabel('年冲淤厚度 (m)',fontdict=pop)
ax1.set_xlabel('年份',fontdict=pop)
ax1.tick_params(labelsize=30,axis='y')
ax1.tick_params(labelsize=18,axis='x',rotation=45)
ax2.tick_params(labelsize=20,axis='y')
labels = ax1.get_xticklabels() + ax1.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels]
ax1.yaxis.set_major_locator(ticker.MultipleLocator(tick_spacing))
plt.gcf().autofmt_xdate()
plt.savefig(r'.\3_1.jpg',dpi = 800)
plt.show()
posted @ 2020-10-09 18:06  云飞01  阅读(184)  评论(0编辑  收藏  举报