python - trellis plots with pandas.tools.rplots: axes labels -
i'm having hard time getting pandas.tools.rplots label axes. here's minimal example:
import pandas pd import pandas.tools.rplot rplot import numpy np import matplotlib.pyplot plt sitecodes = ['a'] * 10 + ['b'] * 10 + ['c'] * 10 height = np.random.rand(len(sitecodes)) * 1000 obs = np.random.rand(len(sitecodes)) df = pd.dataframe({'sitecodes':sitecodes, 'altitude':altitude, 'obs':obs}) plt.figure() plot = rplot.rplot(df, x='altitude', y='obs') plot.add(rplot.trellisgrid(['sitecodes', '.'])) plot.add(rplot.geomscatter()) discard = plot.render() plt.show() some of examples in http://pandas.pydata.org/pandas-docs/stable/visualization.html#trellis-plotting-interface have axis labels , not; in illustration above mine don't. can't find way add together them in documentation can find or poking around within plot object rplot.rplot returns.
surely there's way label axes?
this might bug or "work in progress" ...
however if @ end of code before plt.show() add together this:
for i, in enumerate(plt.gcf().axes): if a.get_xticks().any(): plt.setp(a, xlabel='altitude') if == 1: plt.setp(a, ylabel='obs') plt.show() it add together x label bottom axe , y label middle axe.
this indeed not universal solution , needs adjusted if x, y dimension of trellis plot different.
edit:
a universal solution add together text figure, done this: instead of discard = plot.render() utilize code:
fig = plt.gcf() fig.text(s='altitude', x=0.5, y=0, ha='center') fig.text(s='obs', x=0, y=0.5, va='center', rotation='vertical') discard = plot.render(fig) this should work regardless of number of axes used in plot.
python pandas trellis
No comments:
Post a Comment