Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7550 views
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 a list for the x values and the y values
7
x_values = []
8
y_values = []
9
10
done = False
11
12
# Read input from the user until they enter an empty string
13
while not done:
14
pair = raw_input('Enter an x,y pair to be plotted: ')
15
16
#Test to see if the user entered the empty string, if not
17
if pair != '':
18
# Input in the form x,y. Break this up into an x value and a y value
19
values = pair.split(",")
20
# Add the x value to a list of x values
21
x_values.append(float(values[0]))
22
# Add the y value to a list of y values
23
y_values.append(float(values[1]))
24
else:
25
done = True
26
27
print 'x values are', x_values, 'and y_values are', y_values
28
29
# Create a plot from the lists of x and y values
30
plt.plot(x_values, y_values)
31
32
# Save the plot into a .png file for later viewing
33
plt.savefig('scatter.png')
34
35