【发布时间】:2015-08-04 08:02:41
【问题描述】:
我指的是已经问过的问题here。
在这个例子中,用户解决了第二个轴的问题,方法是将它添加到图表的上部,它与标题重合。
问题: 是否可以在第一个 x 轴的底部添加第二个 x 轴?
代码:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
X = np.linspace(0,1,1000)
Y = np.cos(X*20)
ax1.plot(X,Y)
ax1.set_xlabel(r"Original x-axis: $X$")
new_tick_locations = np.array([.2, .5, .9])
def tick_function(X):
V = 1/(1+X)
return ["%.3f" % z for z in V]
ax2.set_xticks(new_tick_locations)
ax2.set_xticklabels(tick_function(new_tick_locations))
ax2.set_xlabel(r"Modified x-axis: $1/(1+X)$")
plt.show()
【问题讨论】:
标签: python matplotlib