1 回答

TA贡献1780条经验 获得超5个赞
这是一个示例,带有第二个缩放的顶轴:
import numpy as np
import matplotlib.pyplot as plt
# Some data
x = 12 + 3*np.random.randn(1000)
x_normed = (x - np.mean(x))/np.std(x)
# Graph
fig, ax1 = plt.subplots()
ax1.hist(x_normed, bins=20)
x1_lim = np.array(ax1.get_xlim())
x2_lim = x1_lim*np.std(x) + np.mean(x)
ax2 = ax1.twiny()
ax2.set_xlim(x2_lim)
ax1.set_ylabel('count')
ax1.set_xlabel('normed x', color='k')
ax2.set_xlabel('x', color='k');
反过来做我认为更好:
import numpy as np
import matplotlib.pyplot as plt
# Some data
x = 12 + 3*np.random.randn(1000)
# Graph
fig, ax1 = plt.subplots()
ax1.hist(x, bins=20)
x1_lim = np.array(ax1.get_xlim())
x2_lim = (x1_lim - np.mean(x))/np.std(x)
ax2 = ax1.twiny()
ax2.set_xlim(x2_lim)
ax1.set_ylabel('count')
ax1.set_xlabel('x', color='k')
ax2.set_xlabel('x normed', color='k');
这使:
添加回答
举报