- 1). Double-click the "Matplotlib PyLab" icon to launch the plotting command line.
- 2). Create the data you want to plot by entering the following code:
"max_x, max_y, min_x, min_y = 11.0, 11.0*11.0, 0.0, 0.0" and press "Enter." - 3). Program arrays so that they plot "X" and "Y" variables by typing the following code into the command line:
"x_arr = []
y_arr = []"
Press "Enter." - 4). Type the following code to fill the arrays with data:
"for i in range(min_x,max_x):
x_arr.append(float(i))
y_arr.append(float(i*i))"
Press "Enter." Normally, the data will be drawn from database queries. - 5). Type the following code to create a FigureCanvas:
"fig = plt.figure()"
Press "Enter." - 6). Place the axis in the "FigureCanvas" by typing the following code:
"ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])"
Press "Enter." You can replace the values with 0.0 to 1.0. - 7). Type the following code to set the minimum and maximum values for each axis:
"ax.set_xlabel('x data')
ax.set_ylabel('y data')
ax.set_xlim(min_x,max_x)
ax.set_ylim(min_y,max_y)"
Press "Enter." - 8). Plot the function by typing the following code:
"ax.plot(x_arr,y_arr, color='red', lw=2)"
Press "Enter."
previous post
next post