I am trying to put two scatter plots next to each other with a shared y axis, but the axis seems to get an odd scale. Without the shared axis the two plots look fine. I also noticed that the problem does not occur when using “plot” instead of “scatter”. Images are included below. Here is the code I am using.
#!/usr/bin/python
import matplotlib.pyplot as plt
fig = plt.figure(1)
for i in range(1,3):
if i == 1:
ax = fig.add_subplot(1,2,i)
else:
fig.add_subplot(1,2,i, sharey=ax)
#plt.plot([5.0], [1],marker="*",color='tomato')
plt.scatter([5.0], [1], s=20, color='tomato')
plt.show()
[I would include images but the site won’t let me as a newbie.] When I run the code above I see plots with a y axis that runs from 0.0000 to 0.0008 with a single point plotted at 0.0004. Without shared axes the y axis goes from 0.94 to 1.06 with a single point plotted at 1.00, as expected.
Can anyone tell me why? Is this a bug or a feature?
matplotlib: 0.99.1.2-3ubuntu on Ubuntu 10.04 LTS – the Lucid Lynx
I’ve no answer to the why question, but here’s how to get rid of it: In your code snippet, giving
scatterthree points to drawworks for me (matplotlib 1.1.0 on Lucid).
I can only guess that
scattertries to be a bit smarter thanplotwith the axes limits,but whatever it’s doing, it goes nuts for just a single point.