2

I am using matplotlib in jupyter notebook

I tried to plot

t=[0.038, 0.019, 0.036, 0.019, 0.009, 0.008, 0.037, 0.036, 0.034,0.09 ]
s=[3.872, 2.526, 5.972, 2.313, 4.132, 4.311, 2.083, 2.365, 9.334,1.616]
k=['o' for i in range(len(s))]
plt.figure(figsize=(5,5))
plt.scatter(t, s)
for i, txt in enumerate(k):
    plt.annotate(txt, (t[i], s[i]))

which gives

enter image description here

then for example, I want to specifically examing points for y range between 4 and 5. I want to set the y plot range and ylim setting is what I found.

t=[0.038, 0.019, 0.036, 0.019, 0.009, 0.008, 0.037, 0.036, 0.034,0.09 ]
s=[3.872, 2.526, 5.972, 2.313, 4.132, 4.311, 2.083, 2.365, 9.334,1.616]
k=['o' for i in range(len(s))]
plt.figure(figsize=(5,5))
plt.scatter(t, s)
for i, txt in enumerate(k):
    plt.annotate(txt, (t[i], s[i]))
plt.ylim([4,5])

this output

enter image description here

Well, the y plot range is right. But note the red circled scroll bar, you can infer how large the margin is!!! So how to correctly control plot range in matplotlib that elimite margin around figures?

Community
  • 1
  • 1
user15964
  • 2,507
  • 2
  • 31
  • 57
  • 1
    this is certainly an annoying bug. goes back even before 2017 [based on this question](https://stackoverflow.com/questions/41990104/matplotlib-inline-rescale-figure-after-xlim-ylim-on-hist2d-plot) – MattR Jan 22 '20 at 17:27
  • @MattR Thank you so much! `%matplotlib notebook` works and it is quite useful. – user15964 Jan 23 '20 at 02:46

0 Answers0