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()