繁体   English   中英

使用matplotlib在2 y轴上使用散点图

[英]Using scatter on 2 y axis with matplotlib

我正在尝试在matplotlib上绘制2条不同的曲线,但是其中之一需要散布,或者没有连接这些点的线。 反正有这样做吗? 现在,我的绘图代码为:

fig, ax1 = plt.subplots()

ax2 = ax1.twinx()
ax1.plot(epoch, list_of_gas, 'b')
ax2.plot(temp_times, temperatures, 'r')

ax1.set_ylabel('Pressure (torr)', color='b')
ax2.set_ylabel('Temperature (Celcius)', color='r')

ax1.set_title(folder + ' - ' + gas)
ax1.set_xlabel('time (seconds)')
ax1.set_xlim([0, 1000000])
ax2.set_ylim([0,425])
ax1.set_yscale('log')
ax1.set_ylim([ymin,ymax])

plt.show()

但是,我想要ax1.scatter(epoch, list_of_gas, 'b') ,但是您不能在2轴上使用散点图。 有谁知道解决这个问题的方法吗? 想删除连接点的线吗?

绝对可以在twinx(双轴,共享x轴)情况下使用散点图:

import numpy as np
import matplotlib.pyplot as plt

x, y = np.random.random((2,50))
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.scatter(x, y, c='b')
ax2.plot(np.sort(x), np.arange(x.size), c='r')

共享x轴的双轴散点图

另外,如果要删除连接数据点的行,则可以添加选项: ls='none'或更长的linestyle='none' ,如matplotlib文档中所述 请记住,与大多数Python库一样,matplotlib选择了明智的默认值。 对于对plot的普通调用,默认值为ls='-'以产生连接的线。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM