Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: CSCI 195
Views: 5931
Image: ubuntu2004
1
# Make the matplotlib and matplotlib.pyplot modules available
2
import matplotlib
3
matplotlib.use("Agg")
4
import matplotlib.pyplot as plt
5
6
# Initialize x_values and y_values to be empty lists
7
x_values = list()
8
y_values = list()
9
10
done = False
11
# Read input from the user until they enter an empty string
12
while not done:
13
line = input('Enter an x,y pair: ')
14
15
# Test to see if the user entered the empty string. If not
16
if line != '':
17
# Break up the current line of input at the “,” location
18
parts = line.split(',')
19
# Add the part to the left of the comma to x values
20
# Add the part to the right of the comma y values
21
x_values.append(int(parts[0]))
22
y_values.append(int(parts[1]))
23
else:
24
done = True
25
26
print (x_values)
27
print (y_values)
28
29
30
# Create a plot from the two lists of values
31
plt.plot(x_values, y_values, 'ro')
32
33
# Save the plot to a file for later viewing
34
plt.savefig('scatter.png')
35