我正在尝试制作类似于:
的颜色幅度图
我有三个包含完全相同数值的数组。
x1
= B-V(-.5到2)
x2
=温度。 (30,000到3000)并且需要是对数刻度
y1
=幅度(因其他人而异)
x1
,x2
和y1
数组都已关联,我想在散点图中将它们一起绘制。
我的代码:
#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()
答案 0 :(得分:1)
如果我正确理解你,你应该能够在图形的右边缘选择一个点,轴应该对齐,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轴需要更多“空间”,将其极限设置为最大值,然后将其转换为另一个轴的坐标空间以使用它作为其限制。