use*_*806 5 python matplotlib scipy
这里的例子 'log'和'symlog'有什么区别? 很好地展示了原点的线性刻度如何与其他地方的对数刻度一起使用.我想走另一条路.我希望从1-100开始有一个对数刻度,然后是线性的!规模从100-1000.我有什么选择?如上图所示这种尝试不起作用
import matplotlib.pyplot as plt
plt.figure()
plt.errorbar(x, y, yerr=yerrors)
plt.xscale('symlog', linthreshx= (100,1000))
Run Code Online (Sandbox Code Playgroud)
问题似乎是linthreshx被定义为取范围(-x,x).因此,如果x为5,我们将得到线性比例(-5,5).一个局限于原点.我认为只是选择一个不同的范围应该有效,但事实并非如此.有任何想法吗?
我假设你想要在原点附近线性,记录更远——因为“符号”是相反的——我无法想出看起来像这样的数据,但你可以把它与轴网格放在一起:
# linear and log axes for the same plot?
# starting with the histogram example from
# http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html
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(xdomain, np.sin(xdomain))
axMain.set_yscale('log')
axMain.set_ylim((0.01, 0.5))
divider = make_axes_locatable(axMain)
axLin = divider.append_axes("top", size=2.0, pad=0.02, sharex=axMain)
axLin.plot(xdomain, np.sin(xdomain))
axLin.set_xscale('linear')
axLin.set_ylim((0.5, 1.5))
plt.title('Linear above, log below')
plt.show()
Run Code Online (Sandbox Code Playgroud)

谢谢.实际上我想要x轴上的log + linear组合而不是y.但我认为你的代码应该很容易适应.
你好!如果你想在x轴上组合log + linear(从Duncan Watts和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')
Run Code Online (Sandbox Code Playgroud)
上面的代码产生: 
(其他)这是一个非常小的修正标题和右侧没有刻度线:
# 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')
Run Code Online (Sandbox Code Playgroud)
添加这些行将为您提供: 
| 归档时间: |
|
| 查看次数: |
5377 次 |
| 最近记录: |