From: Jae-Joon L. <lee...@gm...> - 2009-09-25 03:39:25
|
The example below will give you some idea where to start. It uses twin function in axes_grid toolkit. (also see http://matplotlib.sourceforge.net/examples/axes_grid/parasite_simple2.html) You may use twinx or twiny, but you need to make both x and y axis in sync to each other (maybe using the "xlim_changed" or "ylim_changed" event). To change the title position you set_position method (the coordinate is in normalized axes coordinate). If you need more control, I recommend to use annotate function. Regards, -JJ import matplotlib.transforms as mtransforms import matplotlib.pyplot as plt from mpl_toolkits.axes_grid.parasite_axes import SubplotHost fig = plt.figure() ax1 = SubplotHost(fig, 1,1,1) fig.add_subplot(ax1) ax1.plot([41000, 42000, 43000], [10., 60, 80.]) y_max = 90 aux_trans = mtransforms.Affine2D().scale(3600., y_max) # transform from ax2 to ax1 ax2 = ax1.twin(aux_trans) from matplotlib.dates import DateFormatter, HourLocator locator = HourLocator() ax2.xaxis.set_major_locator(locator) formatter = DateFormatter(r'$%H^h$') ax2.xaxis.set_major_formatter(formatter) t = ax1.set_title("Title") t.set_position((0.5, 1.05)) plt.show() |