这里的例子 What is the difference between 'log' and 'symlog'? 很好地展示了原点处的线性刻度如何与其他地方的对数刻度一起使用。我想走另一条路。我想要一个从 1-100 的对数刻度,然后是线性的!规模从 100-1000。我有哪些选择?如上图 这次尝试没有成功
import matplotlib.pyplot as plt
plt.figure()
plt.errorbar(x, y, yerr=yerrors)
plt.xscale('symlog', linthreshx= (100,1000))
问题似乎是 linthreshx 被定义为取范围 (-x,x)。因此,如果 x if 5,我们将在 (-5,5) 上得到一个线性比例。一是局限于产地。我认为简单地选择一个不同的范围应该有效,但事实并非如此。有什么想法吗?
最佳答案
From the response of user1318806 to cphlewis :
Thank you. Actually I wanted a combination of log+linear on the x axis not y. But I assume your code should be easily adaptable.
您好!如果你想在 x 轴上使用 log+linear 的组合(从 Duncan Watts and CubeJockey 的代码中模式化):
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
# Numbers from -50 to 50, with 0.1 as step
xdomain = np.arange(-50,50, 0.1)
axMain = plt.subplot(111)
axMain.plot(np.sin(xdomain), xdomain)
axMain.set_xscale('linear')
axMain.set_xlim((0.5, 1.5))
axMain.spines['left'].set_visible(False)
axMain.yaxis.set_ticks_position('right')
axMain.yaxis.set_visible(False)
divider = make_axes_locatable(axMain)
axLin = divider.append_axes("left", size=2.0, pad=0, sharey=axMain)
axLin.set_xscale('log')
axLin.set_xlim((0.01, 0.5))
axLin.plot(np.sin(xdomain), xdomain)
axLin.spines['right'].set_visible(False)
axLin.yaxis.set_ticks_position('left')
plt.setp(axLin.get_xticklabels(), visible=True)
plt.title('Linear right, log left')
上面的代码产生:
(MISCELLANEOUS)这是对标题的一个非常小的修正,并且右侧没有刻度线:
# Fix for: title + no tick marks on the right side of the plot
ax2 = axLin.twinx()
ax2.spines['left'].set_visible(False)
ax2.tick_params(axis='y',which='both',labelright='off')
添加这些行将为您提供:
关于python - 在 matplotlib 中结合对数和线性刻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21746491/