Reputation: 363
I just started with a tutorial on Seaborn from a book; 'Python Data Science Handbook'. When I execute the part about adding a legend to the plot, the plot figures goes blank.
I entered these lines of code one by one in my Spyder console
import matplotlib.pyplot as plt
import numpy as np
rng = np.random.RandomState(0)
x = np.linspace(0, 10, 500)
y = np.cumsum(rng.randn(500, 6), 0)
plt.plot(x, y)
Then followed by
plt.legend('ABCDEF', ncol=2, loc='upper left');
Can't understand why the plot figure goes blank. And I have the latest version of Seaborn installed.
Upvotes: 0
Views: 675
Reputation: 2251
You have to run code together:
import matplotlib.pyplot as plt
import numpy as np
rng = np.random.RandomState(0)
x = np.linspace(0, 10, 500)
y = np.cumsum(rng.randn(500, 6), 0)
plt.plot(x, y)
plt.legend('ABCDEF', ncol=2, loc='upper left');
this results:
but fi we run first just plotting and on separate cell legend, we will get:
because plt.legend
by itself tries to create legend on empty fig that has no data
Upvotes: 2