previous:Python Numpy Loading data files and operation
In this article I will be making sine and cosine graph and use matplotlib library of python and its functions.First I will describe the functions then , I will show you the code and output.I will end this article with some specifications to make you understand the code clearly.
As the name clearly suggests , it plots the points.Its two most importatnt parameter are x-axis and y-axis 1d array.
with xlim and ylim functions , we can limit the graph in x axis and yaxis
xticks,yticks are used to display points required for the clarity of the graph.
helps to create an object to get the current axes
to generate the legend of the graph generated using the labels of the functions plotted.
import matplotlib.pyplot as plt
import numpy as np
plt.xticks([-2*np.pi,-np.pi,0,np.pi,2*np.pi],[r'$-2\pi$', r'$-\pi$', r'$0$', r'$+\pi$', r'$+2\pi$'])
4th line contains np.pi which is used for the value of pi that is 22/7
6th line has properties like linewidth (for settinf thickness of line generated),color,label(used for setting label for legend)
9th line, if we change it to plt.ylim(1,6) the plotted graph will be something like this:
10th line , we have parameter a bit different that the 11th line,which are character representation -2pi to 2pi
11th line,remember that tick functions and lim functions are different,if line changed as plt.yticks([-1,-0.5,0,0.5,1,2]) graph will be something like this:
12th line an object is created of name ax
the spines in 13th,14th,16th,18th are actually selectors of the boundaries of graph
the set_color attribute is used to make right and top spine invisible by setting the value none.also without lines
12 to 18 graph would look something like this:
15th and 17th line are used for setting the tick position
16th and 18th line are used for intersection of two axes in 0,0
19th line has plt.legend with attribute loc='lower left' so that legend will be displayed at lower left positions.
other positions are:
next:Python Matplotlib plotting a pie chart