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

11
  • "log scales don't like macs" - that's an interesting theory, but I suspect that you rather simply have a buggy version of matplotlib installed. You may update matplotlib and see if that fixes it. Commented Jun 13, 2018 at 1:15
  • Under your recommendation, I reinstalled matplotlib and checked the version i'm using (2.2.2). Still no luck :/ Commented Jun 13, 2018 at 1:50
  • Can you update your question with a minimal reproducible example, i.e. a code one can run and the images you obtain from that updated version? Commented Jun 13, 2018 at 1:59
  • Added a section under the bold for you. Nothing has changed as far as I can tell. Commented Jun 13, 2018 at 2:23
  • Yes, seems like you aren't using the matplotlib version that you installed but still the old one. Commented Jun 13, 2018 at 9:41

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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 Try adding matplotlib.use('TkAgg') before you plot. If that doesn't work, try just 'Agg', maybe 'GTK'.
No luck. Tried all of them and they made what would be the graph just appear as a white window.
@pierre700 try the different backends listed here. If none of those work then I'm out of guesses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.