-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
version 0.12.0: problems interacting subplots and DataFrame().hist() #4408
Comments
@bluefir while this is being fixed: fyi you should really be using the plotting API not the pylab stuff that tries to imitate matlab by mutating a lot of global state in the interactive shell (i'm not dissing it, but it makes it difficult to make a somewhat uniform API (in pandas) when you have to keep track of a bunch of global state) for the record i like using the matlab-ish API, but not when i write plotting code for reuse. here's some code to do what you want that uses the matplotlib API (and doesn't have the above error) def weight_hists(field, name, bins=100, flag_inline=False):
if flag_inline:
figsize = 16, 8
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=figsize)
portfolio_data[field].hist(ax=ax1, normed=True, bins=bins)
ax1.set_title('{}: All'.format(name))
portfolio_data.ix[portfolio_data[field] != 0, field].hist(ax=ax2, normed=True, bins=bins)
ax2.set_title('{}: Non-Zero'.format(name)) |
I meet this kind problem after upgrading from 0.11 to 0.12 . In 0.11, def df_hist(df, title_str="", p=0, bins=None):
#draw histgram for each dataframe column, filter_dt = dt[(dt>dt.quantile(p)) & (dt<dt.quantile(1-p))]
fig = plt.figure()
plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=0.90)
plt.subplots_adjust(hspace = 0.3) # the amount of height reserved for white space between subplots, wspace
col_qty = len(df.columns)
for i, col in enumerate(df.columns):
dt = df[col]
filter_dt = dt[(dt>dt.quantile(p)) & (dt<dt.quantile(1-p))]
stat = filter_dt.describe().to_dict()
draw_bins = (math.sqrt(len(dt)) if bins is None else bins)
plt.subplot(col_qty, 1, i+1)
filter_dt.hist(normed=True, color='green', alpha=0.5, bins=draw_bins)
plt.axis(xmin=stat['min'],xmax=stat['max'])
mu, sigma, med = stat['mean'], stat['std'], stat['50%']
plt.title('%s '%(col) + r'$\mu=%0.4f,\ \sigma=%0.4f,\ median=%0.4f, \ p=%0.2f $'%(mu, sigma, med, p), fontproperties=TITLE_FONT)
plt.axvline(med, linewidth=3, color='r')
plt.suptitle('Histogram')
return fig |
ok i can fix this tonight probably...i've figured out what issue is.. |
nice... this was simple fix...now i need a way to test that there's no overlap.... to the matplotlib source code mobile! |
@halleygithub use |
I run Python 2.7.5 on Windows 7 64-bit and IPython 0.13.2.
I have a data frame with some portfolio weights and I do the following:
With pandas 0.11.0, running
in IPython with
and
I get
Doing the same thing with pandas 0.12.0 results in
The text was updated successfully, but these errors were encountered: