python 散点图 多个Y轴 2022-11-10 10:52 75阅读 0赞 包括改变了各个轴及标签的颜色 # -*- coding: utf-8 -*- """ Created on Tue Mar 9 20:04:01 2021 @author: 11chen """ #该程序为了绘制散点图,即横坐标为时间,纵坐标有四个 import matplotlib.pyplot as plt import numpy as np import pandas as pd data=pd.read_csv(r"H:\mission\LNG\AISgfffgfue.csv") #extent_LS.csv data['datetime'] = pd.to_datetime(data['datetime']) c = data['piomas'] c[c==-1]=np.nan data['piomas'].replace(-1,np.nan) data['piomas']=c colors = ['black','orange' , 'blue','red','purple'] labels = ['ship speed', 'a','b','c', 'd'] data=data.resample('1T', on='datetime').mean() data=data.reset_index(drop=False) data=data.dropna(axis=0,how='any') #drop all rows that have any NaN values # data.to_csv(r"H:\mission\LNG\AIS\20210104_20210119\csv\209351000_AIS_position_1T.csv") data=data.resample('12H', on='datetime').mean() data=data.reset_index(drop=False) data=data.dropna(axis=0,how='any') #drop all rows that have any NaN values print(data['speed'][0:17].corr(data['smoscs2'][0:17])) print(data['speed'][0:17].corr(data['piomas'][0:17])) def make_patch_spines_invisible(ax): ax.set_frame_on(True) ax.patch.set_visible(False) for sp in ax.spines.values(): sp.set_visible(False) fig, host = plt.subplots(figsize=(16, 7))#, dpi=300 fig.subplots_adjust(top=0.95,bottom=0.1,left=0.05,right=0.8)#0.74 # par1 = host.twinx() par2 = host.twinx() par3 = host.twinx() par4 = host.twinx() # Offset the right spine of par2. The ticks and label have already been # placed on the right by twinx above. # par2.spines["right"].set_position(("axes", 1.1)) #设置坐标的偏移位置 par3.spines["right"].set_position(("axes", 1.1)) #设置坐标的偏移位置 par4.spines["right"].set_position(("axes", 1.2)) #设置坐标的偏移位置 # Having been created by twinx, par2 has its frame off, so the line of its # detached spine is invisible. First, activate the frame but make the patch # and spines invisible. make_patch_spines_invisible(par2) make_patch_spines_invisible(par3) make_patch_spines_invisible(par4) # Second, show the right spine. par2.spines["right"].set_visible(True) par3.spines["right"].set_visible(True) par4.spines["right"].set_visible(True) p1, = host.plot(data['datetime'], data['speed'], color=colors[0],linewidth=3,alpha=1, marker='o', label=labels[0]) # p2, = par1.plot(data['datetime'], data['a'], color=colors[1],alpha=0.5, marker='o', label=labels[1]) p3, = par2.plot(data['datetime'], data['b'], color=colors[2],linewidth=3, alpha=1,marker='o', label=labels[2]) p4, = par3.plot(data['datetime'], data['c'], color=colors[3], linewidth=3,alpha=1,marker='o', label=labels[3]) p5, = par4.plot(data['datetime'], data['d'], color=colors[4],linewidth=3, alpha=1,marker='o', label=labels[4]) host.set_xlim(min(data['datetime']), max(data['datetime'])) host.set_ylim(0, 18) # par1.set_ylim(0, 2.5) par2.set_ylim(0, 2.5) par3.set_ylim(0, 2.5) par4.set_ylim(0, 100) host.set_xlabel("date and time",fontdict={'weight': 'normal', 'size': 19}) host.set_ylabel(labels[0]+' (kn)',fontdict={'weight': 'normal', 'size': 19}) # par1.set_ylabel(labels[1]+'(m)',fontdict={'weight': 'normal', 'size': 16}) par2.set_ylabel(labels[2]+ ' (m)',fontdict={'weight': 'normal', 'size': 19}) par3.set_ylabel(labels[3]+ ' (m)',fontdict={'weight': 'normal', 'size': 19}) par4.set_ylabel(labels[4]+ ' (%)',fontdict={'weight': 'normal', 'size': 19}) host.yaxis.label.set_color(p1.get_color()) # par1.yaxis.label.set_color(p2.get_color()) par2.yaxis.label.set_color(p3.get_color()) par3.yaxis.label.set_color(p4.get_color()) par4.yaxis.label.set_color(p5.get_color()) host.spines["right"].set_color(p1.get_color()) par2.spines["right"].set_color(p3.get_color()) par3.spines["right"].set_color(p4.get_color()) par4.spines["right"].set_color(p5.get_color()) tkw = dict(size=4, width=1.5,labelsize=16) host.tick_params(axis='y', colors=p1.get_color(), **tkw) # par1.tick_params(axis='y', colors=p2.get_color(), **tkw) par2.tick_params(axis='y', colors=p3.get_color(), **tkw) par3.tick_params(axis='y', colors=p4.get_color(), **tkw) par4.tick_params(axis='y', colors=p5.get_color(), **tkw) host.tick_params(axis='x',**tkw) lines = [p1, p3,p4,p5]#p2, # host.legend(lines, [l.get_label() for l in lines],loc="upper center",bbox_to_anchor=(0.5,1.125),prop={ #0.65 1.1 # 'weight' : 'normal', # 'size' : 20, # }, ncol=5) plt.savefig(r'H:\mission\speed_scatter_12H.png', dpi=300) plt.show()
相关 Python | 屏蔽散点图 Masking a scatter plot refers to differentiating a data point with respect to a function 逃离我推掉我的手/ 2023年03月05日 09:51/ 0 赞/ 64 阅读
相关 Python | 散点图 Inherited from the [Dot Plots][], Scatter plots are of very similar types. It provides a - 日理万妓/ 2023年03月05日 08:30/ 0 赞/ 91 阅读
相关 多Y轴曲线 echarts的链接地址 [https://www.makeapie.com/editor.html?c=xPq8II7iqp][https_www.makeapie.com - 日理万妓/ 2023年01月20日 09:38/ 0 赞/ 24 阅读
相关 python 散点图 多个Y轴 包括改变了各个轴及标签的颜色 -- coding: utf-8 -- """ Created on Tue Mar 9 20:04:01 202 ﹏ヽ暗。殇╰゛Y/ 2022年11月10日 10:52/ 0 赞/ 76 阅读
相关 java 散点图_JFreeChart :快速散点图演示 /\ =========================================================== \ JFreeChart : a free ch r囧r小猫/ 2022年11月05日 10:54/ 0 赞/ 178 阅读
相关 Python可视化-散点图与彩色散点图 散点图与彩色散点图都是表示XY轴坐标之间的变化关系。 但是彩色散点图中点的颜色各有不同。 一、数据文件准备 1、value.txt 0,3.19 1 野性酷女/ 2022年05月26日 03:07/ 0 赞/ 188 阅读
相关 python | matplotlib画散点图 1.散点图(scatter) 功能:散点图多用于表征两个变量之间的相关性。 ![aHR0cHM6Ly91cGxvYWQtaW1hZ2VzLmppYW5zaHUuaW8v 雨点打透心脏的1/2处/ 2021年12月14日 08:47/ 0 赞/ 228 阅读
相关 python画散点图 1. 二维散点图 import matplotlib.pyplot as plt import numpy as np data=np.random 我会带着你远行/ 2021年10月19日 01:42/ 0 赞/ 285 阅读
相关 matplotlab如何添加多条轴【2个X轴和2个Y轴】【共享轴】 创建一条共享X或Y轴和新的Y或X轴的Axes对象! ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cH 古城微笑少年丶/ 2021年08月13日 19:57/ 0 赞/ 395 阅读
还没有评论,来说两句吧...