4

In the following code that generates a log-log plot, python picks an x range that does not show the points on the scatter plot

import matplotlib.pyplot as plt

plt.scatter([.005,.005],[1,2])
plt.xscale('log')
plt.yscale('log')
plt.show()

Additionally, if you instead use the following code, it works fine:

import matplotlib.pyplot as plt

plt.plot([.005,.005],[1,2])
plt.xscale('log')
plt.yscale('log')
plt.show()

Usually python picks a good range for both the x and y values. Why does it not in this case?

Please note that I am aware it is possible to change the x and y ranges so that the default is not used. My question is specifically asking why python does not choose a good range in this case.

Thanks

I appears this is a duplicate of Why does matplotlib require setting log scale before plt.scatter() but not plt.plot()?

To anyone reading this, please let me know if I should remove this question or if you'd recommend something else. Thanks

5
  • What's strange is that plt.plot([.005,.005],[1,2], 'o') works fine Commented Sep 30, 2018 at 1:32
  • you have a good point, that is very strange, I'll add that to the question, thanks Commented Sep 30, 2018 at 1:34
  • A similar issue had been raised here. If you look at the end of the discussion, you will find the same alternate as I suggested: use plt.plot with o as markers Commented Sep 30, 2018 at 1:39
  • your link provides a link back to a SO question that is unanswered: stackoverflow.com/questions/38800189/… Commented Sep 30, 2018 at 1:42
  • I didn't go through the complete thread of discussion but I thought of just sharing it with you. @ImportanceOfBeingEarnest might be aware of updates. Wait for his response. Commented Sep 30, 2018 at 1:48

1 Answer 1

6

Judging from various threads (this issue, this issue, this issue, this question) we can conclude that this is a probematic issue to solve. ...but only if you require to set the scale after the plotting.

If you set the scale before plotting, it's not a problem:

import matplotlib.pyplot as plt

plt.xscale('log')
plt.yscale('log')
plt.scatter([.005,.005],[1,2])

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

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.