直径上代码
#!usr/bin/env python # -*- coding:utf-8 -*- """ @author: Suyue @file: dryzhexian.py @time: 2024/05/16 @desc: """ import pandas as pd import matplotlib import matplotlib.pyplot as plt import matplotlib.ticker as ticker from matplotlib.pyplot import MultipleLocator matplotlib.rc("font",family='YouYuan') # 第一张图 input_file = 'I:/soil/dryzhexian/乌审旗_class.xlsx' # 设置图片大小,精度 plt.figure(figsize = (16,8),dpi = 100) df = pd.read_excel(input_file) x = df['time'] y1 = df['PA'] y2 = df['SPI'] y3 = df['MI'] y4 = df['MCI'] y5 = df['Rsm'] # 让x,y刻度线向内 plt.rcParams['xtick.direction'] = 'in' plt.rcParams['ytick.direction'] = 'in' plt.title('乌审旗干旱',fontsize=14) plt.xlabel('时间',fontsize=14) plt.ylabel('干旱等级',fontsize=14) # 创建折线图 plt.plot(x,y1) plt.plot(x,y2) plt.plot(x,y3) plt.plot(x,y4) plt.plot(x,y5) # 设置背景网格线为虚线 plt.grid(linestyle="--") # 设置横轴标记竖着写,字体大小 plt.xticks(x, x, rotation=270) #刻度值字体大小设置(x轴和y轴同时设置) plt.tick_params(labelsize=14) # 设置刻度间隔,x以每5显示,y以每1显示 x_major_locator=MultipleLocator(5) y_major_locator=MultipleLocator(1) ax = plt.gca() ax.xaxis.set_major_locator(x_major_locator) ax.yaxis.set_major_locator(y_major_locator) # 加图释 plt.legend(['PA','SPI','MI','MCI','Rsm'],fontsize=14) # 出图 plt.show()
标签:plot,major,plt,字体大小,locator,python,df,折线图,import From: https://www.cnblogs.com/shirleysu90/p/18197234