How to Integrate a Plotted Function in Python
Python is a high-level programming language that is both object-oriented and functional. It offers automatic memory management and when combined with plug-ins, it can be compiled into executable programs such as plotted functions. The Matplotlib plug-in for Python was designed specifically for storing code libraries for creating plots and is needed to create plotted functions. With Matplotlib, you can create charts and plot functions in Python.
Instructions
-
-
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."
-
1
References
- Matplotlib: Tutorial
- "Learning Python, 3rd Edition"; Mark Lutz; 2007