I am wondering what the comma does in this code:
line, =
The following example shows the behavior:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
print("First:")
print(line)
print("Second:")
line = ax.plot([], [], lw=2)
print(line)
Result:
First:
Line2D(_line0)
Second:
[<matplotlib.lines.Line2D object at 0xb137c4c>]
It really becomes confusing when I try to use the line variable, and I don't know whether to use the trailing comma or not:
def init():
line.set_data([], [])
return line,
Or is there a better way to do this which avoids the comma?