(重编辑:)
在python matplotlib,我要绘制y针对x具有两个xscales,下一个具有线性蜱和上一个具有对数刻度.
较低的x值是较高值的任意函数(在这种情况下是映射func(x)=np.log10(1.0+x)).推论:上x蜱位置与下蜱位置的任意函数相同.
必须将两个轴的数据点位置和刻度位置分离.
我希望上轴的对数刻度位置和标签尽可能整齐.
制作这样一个情节的最佳方法是什么?
相关: http ://matplotlib.1069221.n5.nabble.com/Two-y-axis-with-twinx-only-one-of-them-logscale-td18255.html
类似(但没有答案)的问题?: Matplotlib:如何在对数图中设置孪晶轴的刻度
您可能会发现Axes.twiny()并且Axes.semilogx()有用。
import numpy as np
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots()
x = np.arange(0.01, 10.0, 0.01) # x-axis range
y = np.sin(2*np.pi*x) # simulated signal to plot
ax1.plot(x, y, color="r") # regular plot (red)
ax1.set_xlabel('x')
ax2 = ax1.twiny() # ax1 and ax2 share y-axis
ax2.semilogx(x, y, color="b") # semilog plot (blue)
ax2.set_xlabel('semilogx')
plt.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2656 次 |
| 最近记录: |