Plotting Basics
Plotting is very easy in mathplot and is done using pyplot.plot() function. plot()
Plotting a line graph
Plotting multiple line graphs
Matplot supports plotting of multiple graphs on a plot. But when multiple types of graphs appear in a single plot, it becomes harder to differentiate each graph. we use legends, labels and color to fix this challenge.
- we use
- plt.xlabel() to label X axis
- plt.ylabel() to label Y axis
- plt.title() to give a name
- In order to create legends, we label the dataset with a label name Dataset 1 and Dataset 2 at the time of plotting and call the plt.legend() function
Plotting a Linear Equation
A graph has x and y axis, and values of x changes with respect to y or vice versa. You get a line if the ratio is constant. Lets try to solve a linear equation set using matplot.
f(y) = 2x + 3 …. (1)
f(y) = 3x – 9 …. (2)
we create two functions each for eq(1) and eq(2), run on a small sample of plots, here 30 data points and plot the graph. The intersection of two lines gives the solution for this equation.