本文主要是介绍python matplot 纵坐标非均匀折线图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 13 23:10:39 2022@author: sun
"""import matplotlib.pyplot as plt #导入Matplotlib
import csv
import numpy as np
import math
# 导入字体属性包
from matplotlib.font_manager import FontProperties
#plt.rcParams['font.sans-serif'] = ['wqy-microhei'] #用来正常显示中文标签
#plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
#指定中文字体所在的位置
font = FontProperties(fname=r"/home/sun/simhei.ttf", size=20)
x =['20','50','80','100','300','500','800','1000','3000','5000','8000','10000','20000','50000','80000','100000'] #此处也可数字
header=[]
data=[]# 以读方式打开文件
with open("result.csv", mode="r", encoding="utf-8-sig") as f:# 基于打开的文件,创建csv.reader实例reader = csv.reader(f)header = next(reader)# 逐行获取数据,并输出for row in reader:data.append(row)
steps=[50,80,100,300,500,800,1000,3000,5000,8000,10000,20000,50000,80000,100000,200000,500000,800000,1000000]
for step in steps:y1=[]y2=[]y3=[]y4=[]y5=[]y6=[]for row in data:if int(row[0])==step:y1.append(float(row[2]))y2.append(float(row[3]))y3.append(float(row[4]))y4.append(float(row[5]))#y5.append(float(row[6]))y6.append(float(row[7]))plt.figure(figsize = (12, 9)) #设置图像大小,当然可以设成方形(12,8)挺合适plt.plot(x,y1,linewidth =1.5, label ='no',color='k', linestyle='-',marker='o',markersize=10) #功能依次为线粗、标签(图例)、颜色、线类型、点形状plt.plot(x,y2,linewidth =1.5, label ='our1',color='k', linestyle='--',marker='X',markersize=10) #功能依次为线粗、标签(图例)、颜色、线类型、点形状plt.plot(x,y3,linewidth =1.5, label ='our2',color='k', linestyle='-.',marker='D',markersize=10) #功能依次为线粗、标签(图例)、颜色、线类型、点形状plt.plot(x,y4,linewidth =1.5, label ='kd-tree',color='k', linestyle=':',marker='^',markersize=10) #功能依次为线粗、标签(图例)、颜色、线类型、点形状#plt.plot(x,y5,linewidth =1.5, label ='r-tree',color='k', linestyle='-',marker='v') #功能依次为线粗、标签(图例)、颜色、线类型、点形状plt.plot(x,y6,linewidth =1.5, label ='quad-tree',color='k', linestyle=(0,[6, 2]),marker='P',markersize=10) #功能依次为线粗、标签(图例)、颜色、线类型、点形状ax = plt.subplot(111) #这是画布哦,说明只在一张图显示,也可分割多图ax.spines['top'].set_visible(False)ax.spines['right'].set_visible(False)plt.xticks(fontsize=11)#嗯调调字体plt.yscale("log")yticks = [0.5,1,1.5,2,2.5,3]plt.yticks(ticks=yticks,labels=['0.5','1','1.5','2','2.5','3'],fontsize=11)plt.ylim(0, 3) #显示的y轴范围plt.xlabel('兴趣范围(m)', FontProperties=font) # x轴名称plt.ylabel('耗时(s)', FontProperties=font) # y轴名称#plt.title('间隔'+str(step)+'m',FontProperties=font) #标题plt.legend(loc='center right', borderaxespad=0,prop=font) #显示图例plt.savefig('pic-{}.png'.format(step),dpi=300,bbox_inches='tight')#plt.show() #显示作图结果
这篇关于python matplot 纵坐标非均匀折线图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!