0

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()

enter image description here

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:

enter image description here

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

Francesco Cariaggi
  • 688
  • 2
  • 9
  • 23
  • 1
    This thread might be helpful: https://stackoverflow.com/questions/16382917/matplotlib-logarithmic-scale-with-zero-value – Bogdan Osyka Jun 18 '18 at 14:55

1 Answers1

1

I solved changing the following line:

plt.xscale('log')

with this line:

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

which finally yields the desired result:

enter image description here

Francesco Cariaggi
  • 688
  • 2
  • 9
  • 23