pierre700
pierre700

Reputation: 11

Label and tick marks disappear when using log scale in matplotlib python

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

Upvotes: 0

Views: 1746

Answers (1)

Engineero
Engineero

Reputation: 12948

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...

Upvotes: 1

Related Questions