1

I am drawing graph in tkinter using matplotlib. Here is code:

data = [[left[0],right[0]]]
X = ["left", "right"]

fig = Figure(figsize=(6, 4), dpi=96)
ax = fig.add_subplot(111)

barlist = ax.bar(X , data[0], color = 'b', width = 0.25)


barlist[0].set_color('r')

graph = FigureCanvasTkAgg(fig, master=win)
canvas = graph.get_tk_widget()
canvas.place(x= 150, y = 5)

How do I set y axis limit (maximum value)?

pink puffles
  • 93
  • 1
  • 10

1 Answers1

2

You could do:

ax.set_ylim(lower_limit,upper_limit)
Arco Bast
  • 3,595
  • 2
  • 26
  • 53
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Adrian Mole Mar 19 '20 at 20:44
  • To my understanding, the question was how to set the axis limit in a matplotlib plot. My answer shows how to do that. I am unaware of any "how and why" or "limitations and assumptions" on which I could elaborate further. – Arco Bast Mar 19 '20 at 22:46
  • @AdrianMole actually, I've noticed by looking at your profile that your usual focus is not on python ... so may I ask whether you found my answer by some review queue? – Arco Bast Mar 19 '20 at 22:51
  • You are correct - it came up in Review (Low Quality Posts). So, somebody else had sent it there and it seems that I reviewed it too hastily - not looking more carefully at the context. Please accept my apologies! (I can delete the comment but, alas, cannot undo my review.) – Adrian Mole Mar 19 '20 at 23:12
  • No need to apologize. Thanks for the feedback. I'd suggest to leave the comments. – Arco Bast Mar 19 '20 at 23:14