Matplotlib Basics Flashcards
How do you draw a plot using matplotlib?
From matplotlib import pyplot as plt
Plt.plot()
What arguments does plt.plot() take and what do they mean?
Plt.plot() takes 2 main arguments, X and y values, then it can take additional arguments such as marker, colour,linewidth,label
X and y arguments decide how the plot looks, marker changes the way the line looks, colour changes the colour of the line, linewidth changes the weight of the line, label assigns a name that can later be displayed using plt.legend()
How do you name X and y axis?
You can use plt.xlabel(‘name’) and plt.ylabel(‘name’) to do that
How do you name the whole plot?
You can use plt.title(‘title’) to do that
How can you display the labels
You can use plt.legend() to do that
What arguments does plt.legend() take?
Plt.legend() takes loc= as argument, it can takes a string like ‘upper left’ as a value or a tuple which corresponds % of how far away from bottom left the legend should be, for example (0.02,0.05)
How do you create a grid?
You can use plt.grid(True)
How do you create a layout that fits on your display?
You can use plt.tight_layout()
How can you save what you made on your disc?
Plt.savefig(‘’)
How can you display the figure you made?
Plt.show()
How can you create a bar?
Plt.bar()
How can you create a horizontal bar plot
Plt.barh()
How can you create a pie chart?
Plt.pie()
What arguments can plt.pie() take and what do they do?
Labels,slices,colors,shadow,explode,wedgeprops={edgecolor:},startangle,autopct. Labels=labels names each slice, slices=slices sets a part for every slice, colors=colors sets a color for each slice, shadow=true creates a shadow for the pie, explode=Xplode gets one slice away from others. Autopct rounds the values
How can you create a scatterplot?
plt.scatter()
What arguments does scatterplot take and what do they change?
C,marker,alpha,edgecolor,cmap,s,X,y
C stands for color,s stands for size,marker changes the symbol, alpha sets how see through it is , X,y set coordinates, cmap sets the color scheme,edgecolor sets the color of the edge
What’s a colorbar and how do you create it?
Colorbar is like a legend for the colours on the scatterplot
Clrbar= plt.colorbar()
Clrbar has it’s own functions for example clrbar.set_label(‘’)
How would you change the X and y values to their logarithmic expressions
Plt.xscale(‘log’),plt.yscale(‘log’)
How can you create a stack plot?
You can do that by using plt.stackplot()
What arguments does the plt.stackplot() take?
X values , y values * n, labels,colors
X values argument sets X values there can only be one, yvalues set the y plane and are stacked on top of each other there can be multiple, labels=labels names the values, colors=colors gives the values set colors