Matplotlib/pyplot: How to enforce axis range?

前端 未结 4 1687
时光取名叫无心
时光取名叫无心 2020-12-14 05:40

I would like to draw a standard 2D line graph with pylot, but force the axes\' values to be between 0 and 600 on the x, and 10k and 20k on the y. Let me go with an example.

4条回答
  •  伪装坚强ぢ
    2020-12-14 06:15

    Calling p.plot after setting the limits is why it is rescaling. You are correct in that turning autoscaling off will get the right answer, but so will calling xlim() or ylim() after your plot command.

    I use this quite a lot to invert the x axis, I work in astronomy and we use a magnitude system which is backwards (ie. brighter stars have a smaller magnitude) so I usually swap the limits with

    lims = xlim()
    xlim([lims[1], lims[0]]) 
    

提交回复
热议问题