Investigating Simple Pyplot Examples

Using Pyplot Simple Examples, paste the first example into your Python editor.

INVESTIGATE QUESTIONS – plt.plot() (Line Graph)

What does each list (x and y) represent in the graph?
How do we know which axis is which?
What happens if you make the two lists different lengths?
What happens if you leave one list empty?
How does the shape of the line change if you add a new x–y pair at the end?
Try changing plt.plot(x, y) to plt.plot(y, x). What happens?
Try adding plt.plot(x, y, ‘r–‘). What do the letters mean?
What happens if you run the code but forget plt.show()?

MODIFY – plt.plot() (Line Graph)

Add one more number to both the x and y lists, then run the code again to see the new point appear.
Make a second line on the same graph by adding this code before plt.show():
plt.plot(x, [5, 10, 20, 40, 80])
Give the graph a title by adding this before plt.show():
plt.title(‘My First Line Graph’)
Label the axes. Add these lines before plt.show():
plt.xlabel(‘X values’)
plt.ylabel(‘Y values’)

INVESTIGATE  – plt.scatter() (Scatter Plot)

How does the scatter plot look different from the line graph using the same data?
Which chart better shows connections over time? Which shows individual data points?
Why might you prefer scatter instead of plot for certain kinds of data?
What happens if two points have the same x-value?
What if all the y-values are the same?
Change the code to plt.scatter(x, y, color=’red’) or plt.scatter(x, y, marker=’x’). What changed in the appearance?
What happens if one list has an extra number?

MODIFY – plt.scatter() (Scatter Plot)

Add one more x value and one more y value to see a new point appear.
Give the graph a title by adding this before plt.show():
plt.title(‘My First Scatter Plot’)
Label the axes. Add these before plt.show():
plt.xlabel(‘X values’)
plt.ylabel(‘Y values’)

This page was created with GenAI and Human editing.