1

Thanks in advance for taking the time to read my question. I'm having trouble plotting an array of negative powers of 10 in matplotlib

I have read through all of the log xscale options in the matplotlib documentation but to no avail. I have also read the following questions and some others which seemed similar but they did not end up helping me out:

Matplotlib: disable powers of ten in log plot

Plot Axis in Python with Log Scale for Negative Exponents of 10

Logscale plots with zero values in matplotlib *with negative exponents*

Logscale plots with zero values in matplotlib

This is more or less in simple form what my code looks like.

x = np array with 100 values of 0.99999, 0.9999, 0.999, 0.99

y = np array with corresponding evaluation outputs to be plotted.

plt.plot(x, y, 'o')
plt.xticks([0.99999,0.9999,0.999,0.99])
plt.gca().set_xscale('log')

What I'm trying to attain is a plot with just the values 0.99999, 0.9999, 0.999, 0.99 evenly spaced on the x axis plotted against their corresponding y values.

Once again I would like to thank you so much for taking the time to read this question, and I sincerely hope you can help me out!

Peter Leimbigler
  • 10,775
  • 1
  • 23
  • 37
A. Hartman
  • 83
  • 1
  • 2
  • 8
  • 2
    Could you post a minimal and complete example, including some copy-pastable example data? – Peter Leimbigler May 28 '19 at 21:01
  • `0.99999,0.9999,0.999,0.99` is not a logarithmic progression, so it is no surprise it is not evenly-spaced with a log scale. Have you considered plotting `1-x` instead? – Leporello May 29 '19 at 08:55

1 Answers1

2

You could easily "fake" this kind of plot, by plotting y against [0,1,2,3,...] and then replacing the xtickslabel with [0.9999,0.999,0.99,...]

x = [0.99999,0.9999,0.999,0.99]
y = [1,2,3,4]
fig, ax = plt.subplots()
ax.plot(range(len(x)),y, 'o-')
ax.set_xticks(range(len(x)))
ax.set_xticklabels(x)

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75
  • Thank you so much! This answer lead me on the path to create the plot that I wanted. Very much appreciated!! – A. Hartman May 29 '19 at 07:11