python - X labels matplotlib -


i want change x axis years. years saves in variable years.

i want make plot of data looks this: it should image

however, not able create x axes years. plot looks following image: this example of produced image code

my code looks follows:

import pandas pd import matplotlib.pyplot plt  data = pd.read_csv("data1.csv") demand = data["demand"] years = data["year"] plt.plot( demand, color='black') plt.xlabel("year") plt.ylabel("demand (gw)") plt.show() 

i thankful advice.

the plot method in example not know scaling of data. so, simplicity treats values of demand being 1 unit apart each other. if want x-axis represent years, have tell matplotlib how many values of demand should treat "one year". if data monthly demand, 12 values per year. , here go:

# setup figure fig, (ax1, ax2) = plt.subplots(2)  # generate random data data = np.random.rand(100)  # plot undesired way ax1.plot(data)  # change tick positions , labels ... ax2.plot(data)  # ... 1 label every 12th value xticks = np.arange(0,100,12)  # ... start counting in year 2000 xlabels = range(2000, 2000+len(xticks))  ax2.set_xticks(xticks) ax2.set_xticklabels(xlabels)  plt.show() 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -