Skip to content

Instantly share code, notes, and snippets.

@tkb
Last active December 20, 2015 00:19
Show Gist options
  • Save tkb/6040597 to your computer and use it in GitHub Desktop.
Save tkb/6040597 to your computer and use it in GitHub Desktop.
import wbdata
import pandas
import matplotlib.pyplot as plt
#set up the countries I want
countries = ["CL","UY","HU"]
#set up the indicator I want (just build up the dict if you want more than one)
indicators = {'NY.GNP.PCAP.CD':'GNI per Capita'}
#grab indicators above for countires above and load into data frame
df = wbdata.get_dataframe(indicators, country=countries, convert_date=False)
#df is "pivoted", pandas' unstack fucntion helps reshape it into something plottable
dfu = df.unstack(level=0)
# a simple matplotlib plot with legend, labels and a title
dfu.plot();
plt.legend(loc='best');
plt.title("GNI Per Capita ($USD, Atlas Method)");
plt.xlabel('Date'); plt.ylabel('GNI Per Capita ($USD, Atlas Method');
@chhantyal
Copy link

plt is defined nowhere. Did you forget to import?

plt.legend(loc='best');

NameError Traceback (most recent call last)
in ()
----> 1 plt.legend(loc='best');

NameError: name 'plt' is not defined

@chhantyal
Copy link

Ah, you are missing this import

import matplotlib.pyplot as plt

@tkb
Copy link
Author

tkb commented Aug 3, 2013

Thanks Neo - updated the gist.

Do you know if you can you do a pull request from your fork?

@chhantyal
Copy link

Ah, that is first thing I tried here. Looks gist doesn't have that functionality yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment