seaborn中的直方图箱尺寸

时间:2017-02-16 04:24:00

标签: python matplotlib histogram seaborn

我使用Seaborn的FacetGrid绘制一些直方图,我认为自动bin大小仅使用每个类别的数据(而不是每个子图),这会导致一些奇怪的结果(参见skinny) y = 2)中的绿色垃圾箱:

g = sns.FacetGrid(df, row='y', hue='category', size=3, aspect=2, sharex='none')
_ = g.map(plt.hist, 'x', alpha=0.6)

Seaborn histogram

有没有办法(使用Seaborn,而不是回到matplotlib)使每个图的直方图箱大小相等?

我知道我可以手动指定所有的bin宽度,但这会强制所有直方图都是相同的x范围(请参阅笔记本)。

笔记本:https://gist.github.com/alexlouden/42b5983f5106ec92c092f8a2697847e6

1 个答案:

答案 0 :(得分:4)

您需要为@Override public boolean onOptionsItemSelected(MenuItem item) { boolean result = true; switch (item.getItemId()) { case R.id.menu_details_save_toggle: if (mIsSaved) { //you could modify this to check the icon/text of the menu item mIsSaved = false; } else { mIsSaved = true; } invalidateOptionsMenu(); //cause a redraw break; default: result = super.onOptionsItemSelected(item); } return result; } @Override public boolean onPrepareOptionsMenu(Menu menu) { if (mIsSaved) { //in production you'd probably be better off keeping a reference to the item menu.findItem(R.id.menu_details_save_toggle) .setIcon(R.drawable.action_saved_on) .setTitle(R.string.action_unsave); } else { menu.findItem(R.id.menu_details_save_toggle) .setIcon(R.drawable.action_saved_off) .setTitle(R.string.action_save); } return super.onPrepareOptionsMenu(menu); } 定义一个包装函数来执行色调分组本身,例如

plt.hist

enter image description here

相关问题