So doing GUI development sucks. Like... really sucks a lot. But sometimes you just want to visualize some data, like with a graph, histogram, or whatever. Sure, you could just copy and paste the data into Excel. But we're programmers, and that thought bores us... (And don't say ANYTHING about VBA, or I'll bludgeon you).
So where is an unhappy programmer to turn in this dire situation? PyLab to the rescue! PyLab (also matplotlib) is a MatLab-like interface for graphing data in Python. It has quite a number of backends, and has a very useful shorthand interface.
For Example:
#!/Library/Frameworks/Python.framework/Versions/Current/bin/python
from pylab import *
from matplotlib.finance import quotes_historical_yahoo
from matplotlib.dates import YearLocator, DayLocator, MonthLocator, DateFormatter
from matplotlib.ticker import FuncFormatter
from datetime import date
d1, d2 = date(2006, 9, 17), date(2007, 9, 17)
msft = quotes_historical_yahoo('MSFT', d1, d2)
intl = quotes_historical_yahoo('INTL', d1, d2)
ax = subplot(111)
plot_date([x[0] for x in msft], [x[1] for x in msft], fmt="b-")
plot_date([x[0] for x in intl], [x[1] for x in intl], fmt="g-")
ax.xaxis.set_major_locator(YearLocator())
ax.xaxis.set_major_formatter(DateFormatter("%Y"))
for tick in ax.xaxis.get_major_ticks():
tick.set_pad(20.)
ax.xaxis.set_minor_locator(MonthLocator())
ax.xaxis.set_minor_formatter(DateFormatter("%b"))
ax.yaxis.set_major_formatter(FuncFormatter(lambda x,y: "$%d"%x))
ax.format_xdata = DateFormatter('%Y-%m-%d')
ax.format_ydata = lambda x: '$%1.2f' % x
grid(1)
legend(('MSFT', 'INTEL'))
ylabel('Opening Price')
show()
Produces:
