0

I need the y-axis of my graph to be on a log scale. When I do so, however, the y-axis' label, tick marks, and title disappear.

plt.figure(2)
plt.semilogy(data2[0, :, 0], sli)
plt.xlabel('n-value')
plt.ylabel('Intensity')
plt.title('Intensity vs. n-shell')
plt.show()

The sli values range from 1.0e-21 to 1.0e-8

I'm not cool enough to post images

When I zoom in far enough though, the label and title actually return but not the tick marks. Don't know if that matters, but thought I'd include it.

!still not cool enough

Thanks

Edit: As it turns out, the code works fine, just not on my mac laptop. I tested the code on a friends computer running ubuntu and it worked perfectly. So, I guess my log scales don't like macs. Still, anybody have any suggestions?

"Update" for @ImportanceOfBeingErnest

Nothing has changed.

Graph produced from my code run with updated mplib

Graph produced from @Engineero 's code run with updated mplib

pierre700
  • 11
  • 6

1 Answers1

1

Try using axis.set_yscale with axis.tick_params. Something like:

fig = plt.figure(2)
axis = fig.add_subplot(111)
axis.plot(data2[0, :, 0], sli)
axis.set_yscale('log', nonposy='clip')
axis.tick_params(axis='y', which='minor', colors='black')
axis.set_xlabel('n-value')
axis.set_ylabel('Intensity')
axis.set_title('Intensity vs. n-shell')
plt.show()

Basically use the axis API. This is the only way I was ever able to get minor log-scale tick marks to work for me the way that I wanted...

Engineero
  • 12,340
  • 5
  • 53
  • 75
  • I plugged your code in and got the exact same thing as my code. Still getting the "error." I'm guessing it has something to do with my mac since the code actually works fine on my friend's linux. Thanks for your contribution though! – pierre700 Jun 12 '18 at 21:58
  • @pierre700 Try adding `matplotlib.use('TkAgg')` before you plot. If that doesn't work, try just 'Agg', maybe 'GTK'. – Engineero Jun 12 '18 at 22:02
  • No luck. Tried all of them and they made what would be the graph just appear as a white window. – pierre700 Jun 12 '18 at 22:18
  • @pierre700 try the different backends listed [here](https://stackoverflow.com/a/43030607/3670871). If none of those work then I'm out of guesses. – Engineero Jun 12 '18 at 22:23