【发布时间】:2018-01-10 15:44:31
【问题描述】:
我想要类似于How to add a second x-axis in matplotlib 的东西,即有一个显示波长的顶部 x 轴和一个显示相应频率的底部轴。
这个情节是用:
#setting up the plot
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.gridspec as gridspec
fig = plt.figure()
fig.tight_layout()
ax = plt.subplot()
#Here it gets interesting!
def tick_function(X):
c = 299792458
V = c/X
V = V*1e6
V = np.round(V,0)
V[2] = 3000
V = V.astype(int)
return(V)
ax = plt.subplot()
ax_top = ax.twiny()
ax.set_xscale("log", nonposx='clip')
ax.set_yscale("log", nonposy='clip')
ax_top.set_xscale("log", nonposx='clip')
ax.set_xlim([8e10,5e14])
ax.set_ylim([5e33,2e36])
axTicks = ax.get_xticks()
ax_top_Ticks = axTicks
ax_top.set_xticks(ax_top_Ticks)
ax_top.set_xlim(ax.get_xlim())
ax_top.set_xbound(ax.get_xbound())
ax_top.set_xticklabels(tick_function(ax_top_Ticks))
现在,我不想在 底部 主要 x 轴的位置绘制 顶部 主要 x 刻度,而是让它们移动。 即,我希望在位置 1000、100、10、1 上放置顶部的主要 x 刻度,而次要刻度相应地移动。
这也是我想要的样子:
我找到了这个情节,这就是我想要的! http://inspirehep.net/record/877424/files/fig2.png 请注意,由于 lambda=c/f 和 ax & ax_top 是对数的,所以小刻度的间距必须反转为!
【问题讨论】:
-
不是 100% 确定您的意思。您能否添加另一个示例屏幕截图来显示您希望该图的外观?
-
您在脚本中使用的
gs1是什么?我需要它来重现您的结果。 -
@lkriener 我更新了,现在只有一个子图而不是令人困惑的网格规范......
-
@DavidG 我上传了一张我正在成像的照片...
标签: python matplotlib