在不同的尺度上,如何操纵多个xax来相互对应?

2024-04-30 02:03:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试制作一个类似于以下内容的颜色幅度图:

B-V Diagram

我有三个数组,它们包含完全相同数量的值。你知道吗

x1=B-V(-.5到2)

x2=温度。(30000到3000)并且需要是对数刻度

y1=震级(根据其他震级而变化)

x1x2y1数组都是链接的,我想用散点图将它们绘制在一起。你知道吗

我的代码:

#PLOTS
x1 = bv_array       #B-V
x2 = t_array        #Temperature
y1 = Vavg_array     #Magnitude
fig = plt.figure()

ax1 = fig.add_subplot(111)
#ax1.xlim(-.5,2)
ax1.plot(x1, y1,'b--')
ax2 = ax1.twiny()
ax2.plot(x2, y1, 'go')
ax2.set_xlabel('Temperature')
ax2.invert_xaxis()

#ax2.xscale('log')
#plt.xscale('log')
#plt.scatter(x,y)

#plt.scatter(bv_array, Vavg_array, s = 1)
plt.gca().invert_yaxis()

plt.show()

Tags: plotfigplt数组arrayx1x2temperature
1条回答
网友
1楼 · 发布于 2024-04-30 02:03:08

如果我理解正确的话,你应该只需要在图的右边缘选取一个点,在那里轴应该对齐,matplotlib将从那里获取它。你知道吗

ax1 = fig.add_subplot(111)

ax1.xlim(-.5,2) # Set it in axis 1 coords

ax1.plot(x1, y1,'b ')
ax2 = ax1.twiny()
ax2.plot(x2, y1, 'go')
ax2.set_xlabel('Temperature')
ax2.invert_xaxis()

ax2.xlim(-2, 3) # Set it in axis 2 coords

要确定点,计算出哪个轴(线性或对数)沿x轴需要更多的“空间”,将其限制设置为其最大值,然后将其转换为另一个轴的坐标空间以将其用作限制。你知道吗

相关问题 更多 >