How to change the range of the x-axis and y-axis in matlibplot?

前端 未结 2 1484
礼貌的吻别
礼貌的吻别 2020-12-16 15:57

I am new to matlibplot and I\'m trying to draw a circle with radius 1 but have both my x and y axis go from 0 to 3 with an increment of 0.25. Right now, I have drawn the gra

相关标签:
2条回答
  • 2020-12-16 16:33

    To change the axes range, you can use

    plt.xlim([-3, 3])
    plt.ylim([-3, 3])
    

    You will then have to remove the line plt.axis('scaled') for this to work.

    import numpy as np
    import matplotlib.pyplot as plt
    import scipy, pylab
    
    plt.axes()
    circle=plt.Circle((0, 0), radius=1, fc='w')
    plt.gca().add_patch(circle)
    plt.xlim([-3, 3])
    plt.ylim([-3, 3])
    plt.yticks(np.arange(-3, 3, 0.25))
    plt.xticks(np.arange(-3, 3, 0.25))
    plt.show()
    
    0 讨论(0)
  • 2020-12-16 16:36

    Use first xticks and yticks before xlim and ylim. This will create an array before it sets the limit

    0 讨论(0)
提交回复
热议问题