arrays and plotting return np exp(- )*np sin( *np pi*xn np linspace( + (xplt plot(xylabel='exp(- )*sin( $\pix)'plt xlabel(' 'label on the axis plt ylabel(' 'label on the axis plt legend(mark the curve plt axis([ - ][tmintmaxyminymaxplt title('my first matplotlib demo'plt savefig('fig pdf'plt savefig('fig png'plt show(make pdf image for reports make png image for web pages the plot resulting from this code is shown in figure most of the lines in the code should be self-explanatorybut some are worth comment the call to legend will create legend for the plotusing the information provided in the label argument passed to plt plot this is very useful when plotting multiple curves in single plot the axis function sets the length of the horizontal and vertical axes these are otherwise set automatically by matplotlibwhich usually works finebut in some cases the plot looks better if we set the axes manually later in this we will create animations of curves andin this casethe axes will have to be set to fixed lengths finallythe two calls to savefig will save our plot in two different file formatsautomatically determined by the file name provided if we plot multiple curves in single plotmatplotlib will choose the color of each curve automatically this default choice usually works wellbut we can control the look of each curve further if desired say we want to plot the functions - sin( pxand - sin( pxin the same plotimport matplotlib pyplot as plt import numpy as np def ( )return np exp(- )*np sin( *np pi*xdef ( )return np exp(- * )*np sin( *np pi*xx np linspace( (xy (xplt plot(xy ' --'label='exp(- )*sin( $\pix)'plt plot(xy ' :'label='exp(- * )*sin( $\pix)'plt xlabel(' 'plt ylabel(' '