This is a bit of a workaround, but it should work consistently:
1. Assign a function to build the binding of a variable (which can also be useful if you need to access some elements of the chart later)
plt.figure(figsize=(3, 3)) plot = plt.plot(range(10), [x*x for x in range(10)], 'o-')
2. Add a “pass” at the bottom of the cell (or an equivalent operation without consequences)
plt.figure(figsize=(3, 3)) plt.plot(range(10), [x*x for x in range(10)], 'o-') pass
3. Add a semicolon at the end of the last statement
plt.figure(figsize=(3, 3)) plt.plot(range(10), [x*x for x in range(10)], 'o-');
source share