This seems a trivial questions, but I could not find the answer anywhere.
When working with lines in mathplotlib, all the tutorials I have seen inicialize the line
variable followed by a comma ,
. Example:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100)
y = np.sin(x)
fig, ax = plt.subplots()
line, = ax.plot(x, y, color='k')
for n in range(len(x)):
line.set_data(x[:n], y[:n])
ax.axis([0, 10, 0, 1])
fig.canvas.draw()
fig.savefig('Frame%03d.png' %n)
Here is another example using a different method.
line, = plt.plot(x, y, '-')
Why do I need this comma ,
? Could I pass another variable after the comma? Does this methods return a tuple? If so, what exactly is being returned?
Some of my graphs seem to work when I don't put the comma, so why do all tutorials have this comma after the variable line
?
edit: It has been pointed out that the method returns a tuple with one element (x, = ... - is this trailing comma the comma operator?), but if this is the case, why not just simply returning the element? Is there a practical use to the tuple? Is there situations where it returns a tuple with more than 1 element?