简体   繁体   中英

Matplotlib logarithmic axis ticks

I have this simple code to plot some values:

ticks = [0, 1e-12, 1e-10, 1e-8, 1e-6, 1e-4]
values = range(1, 7)

plt.plot(ticks, values)
plt.xscale('log')

plt.show()

在此处输入图片说明

The problem is that the point (0, 1) does not get plotted. I tried fixing this by adding one line of code:

ticks = [0, 1e-12, 1e-10, 1e-8, 1e-6, 1e-4]
values = range(1, 7)

plt.plot(ticks, values)
plt.xscale('log')
plt.xticks(ticks) <------- added this line --------

plt.show()

But the result is:

在此处输入图片说明

Which is definitely not what I want. My goal is to correctly plot the point (0, 1) and also set custom ticks in the x-axis, namely the values in ticks (0, 1e-12, 1e-10, 1e-8, 1e-6, 1e-4)

How am I supposed to do that? I've looked around and found no answer

I solved changing the following line:

plt.xscale('log')

with this line:

plt.xscale('symlog', linthreshx=1e-12)

which finally yields the desired result:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM