Reputation: 9
I'm trying to recreate 538's daily show graph. https://fivethirtyeight.com/features/every-guest-jon-stewart-ever-had-on-the-daily-show/
I only got the y axis so far, I am stuck on the x axis.
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
plt.style.use('fivethirtyeight')
x = linspace(0,10);
xticks([0, 5, 10])
xticklabels({'x = 0','x = 5','x = 10'})
#date = [2002, 2003, 2004, 2005]
#N = 5
#ind = np.arange(N)
#plt.xticks((ind, '2000', '04', '08', '12'))
#plt.xticks(["2000", "'04", "'08", "'12"])
#years = mdates.YearLocator()
#yearsFmt = mdates.DateFormatter('%Y')
#ax.xaxis.set_major_locator(years)
#ax.xaxis.set_major_formatter(yearsFmt)
#ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')
#ax.grid(True)
I showed 3 different ways to address the problem. For the uncommented code, I got this error message: name 'linspace' is not defined
.
Upvotes: 0
Views: 47
Reputation: 696
As can be seen in the numpy documentation online, the linspace method is part of the numpy package.
This means that you need to reference the numpy package if you want to use it: you've already imported it as numpy (import numpy as np
), but you must now write x = np.linspace(0, 10);
instead of merely x = linspace(0, 10);
, as you did with other members of the numpy package.
Otherwise, linspace is undefined as far as the Python interpreter is concerned.
Upvotes: 1