Nov-20-2021, 01:37 AM
(This post was last modified: Nov-20-2021, 01:37 AM by Pedroski55.)
I am just trying to do some simple plots, nothing fancy.
So I am trying y = x**2
I thought I set x in the range -4 to +4 with: x = np.arange(-4, 4, 0.2), but I get range 0 to 40 for x. (I suppose there are 40 0.2s in 8)
I would like the zero on the x-axis to coincide with the zero on the y-axis.
2 small problems:
1. How do I set x-axis zero and y-axis zero in the same place?
Ideally, x and y zero should be in the centre of the figure, so I see -4 to +4 on both axes.
2. How can I fix the range of x? (I would like a small interval in the range in order to give a smooth curve.)
So I am trying y = x**2
I thought I set x in the range -4 to +4 with: x = np.arange(-4, 4, 0.2), but I get range 0 to 40 for x. (I suppose there are 40 0.2s in 8)
I would like the zero on the x-axis to coincide with the zero on the y-axis.
2 small problems:
1. How do I set x-axis zero and y-axis zero in the same place?
Ideally, x and y zero should be in the centre of the figure, so I see -4 to +4 on both axes.
2. How can I fix the range of x? (I would like a small interval in the range in order to give a smooth curve.)
def tp(): fig = plt.figure(figsize=(6, 6)) x = np.arange(-4, 4, 0.2) y = x**2 ax = fig.add_subplot(121) #ax2 = fig.add_subplot(122) #ax.fig(num='This is the title') # Move left y-axis and bottom x-axis to centre, passing through (0,0) ax.spines['left'].set_position('center') ax.spines['bottom'].set_position('zero') # Eliminate upper and right axes ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') # Show ticks in the left and lower axes only ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') ax.set_title('Full view') ax.plot(y, color='blue', label='y = x^2') plt.xlabel("X axis") plt.ylabel("Y = x^2") plt.legend() plt.show()