0
0
Matplotlibdata~5 mins

Basic plt.plot usage in Matplotlib - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does plt.plot(x, y) do in matplotlib?
It creates a line plot by connecting points defined by the lists or arrays x and y on the x-axis and y-axis respectively.
Click to reveal answer
beginner
How do you add labels to the x-axis and y-axis in matplotlib?
Use plt.xlabel('label') for the x-axis and plt.ylabel('label') for the y-axis to add descriptive labels.
Click to reveal answer
beginner
What is the purpose of plt.show()?
It displays the plot window with all the current figures and plots. Without it, the plot might not appear in some environments.
Click to reveal answer
beginner
How can you change the line style and color in plt.plot()?
You can add a format string like 'r--' where 'r' is red color and '--' is dashed line. For example, plt.plot(x, y, 'r--').
Click to reveal answer
beginner
What happens if you call plt.plot() multiple times before plt.show()?
All plots are drawn on the same figure, allowing you to overlay multiple lines or data sets in one graph.
Click to reveal answer
What does plt.plot([1, 2, 3], [4, 5, 6]) do?
ACreates a bar chart
BPlots points (4,1), (5,2), (6,3)
CPlots points (1,4), (2,5), (3,6) connected by lines
DCreates a scatter plot without lines
Which command adds a title to a matplotlib plot?
Aplt.title('My Plot')
Bplt.label('My Plot')
Cplt.name('My Plot')
Dplt.header('My Plot')
How do you display the plot after creating it?
Aplt.render()
Bplt.display()
Cplt.draw()
Dplt.show()
What does the format string 'g-.' mean in plt.plot(x, y, 'g-.')?
AGreen dash-dot line
BGray solid line
CGreen dotted line
DGold dashed line
If you want to plot two lines on the same graph, what should you do?
ACall plt.show() twice
BCall plt.plot() twice before plt.show()
CUse plt.plot() only once with combined data
DCreate two separate figures
Explain how to create a simple line plot with labels for x and y axes using matplotlib.
Think about the steps to draw and display a plot with axis descriptions.
You got /4 concepts.
    Describe how to customize the color and line style of a plot line in matplotlib.
    Remember the short string codes like 'r--' for red dashed lines.
    You got /3 concepts.