带有断裂轴和交错色条的直方图 [英] Histogram with breaking axis and interlaced colorbar

查看:98
本文介绍了带有断裂轴和交错色条的直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有那些数据

        a       b       c       d       e
alpha   5.51    0.60    -0.12   26.90   76284.53
beta    3.39    0.94    -0.17   -0.20   -0.20
gamma   7.98    3.34    -1.41   7.74    28394.93
delta   2.29    1.24    0.40    0.29    0.28

我想做一个很好的可发布直方图,就像这样一个

I want to do a nice publishable histogram as this one

但y轴上有一个中断,因此我们可以找出 a b c d的变化 e ,这样,数据就不会被 e 列中的极值所压缩,而是使用隔行扫描的色带直方图:

but with a break in the y axis so we can figure out the variation of a , b , c , d and e so that data will not be squashed by extreme values in e column as this one but using interlaced colorbar histogram:

我想用python(matplotlib,pandas,numpy/scipy)或mathematica或任何其他开放和免费的高级语言(R,scilab等)来实现.谢谢你的帮助.

I would like to do that in python (matplotlib, pandas, numpy/scipy) or in mathematica... or any other open and free high-level language (R, scilab, ...). Thanks for your help.

通过pandas使用matplotlib可以使用"hspace"左下角的选项按钮来调整两个子图之间的空间.

edit: using matplotlib through pandas allows to adjust the space between the two subgraph using option button at bottom left "hspace".

推荐答案

您是否看到过

Have you seen this example? It's for a broken y-axis plot in matplotlib.

希望这会有所帮助.

与大熊猫结合可以得到:

Combining with pandas this gives:

import pandas as pd
import matplotlib.pyplot as plt
from StringIO import StringIO

data = """\
        a       b       c       d       e
alpha   5.51    0.60    -0.12   26.90   76284.53
beta    3.39    0.94    -0.17   -0.20   -0.20
gamma   7.98    3.34    -1.41   7.74    28394.93
delta   2.29    1.24    0.40    0.29    0.28
"""

df = pd.read_csv(StringIO(data), sep='\s+')

f, axis = plt.subplots(2, 1, sharex=True)
df.plot(kind='bar', ax=axis[0])
df.plot(kind='bar', ax=axis[1])
axis[0].set_ylim(20000, 80000)
axis[1].set_ylim(-2, 30)
axis[1].legend().set_visible(False)

axis[0].spines['bottom'].set_visible(False)
axis[1].spines['top'].set_visible(False)
axis[0].xaxis.tick_top()
axis[0].tick_params(labeltop='off')
axis[1].xaxis.tick_bottom()
d = .015
kwargs = dict(transform=axis[0].transAxes, color='k', clip_on=False)
axis[0].plot((-d,+d),(-d,+d), **kwargs)
axis[0].plot((1-d,1+d),(-d,+d), **kwargs)
kwargs.update(transform=axis[1].transAxes)
axis[1].plot((-d,+d),(1-d,1+d), **kwargs)
axis[1].plot((1-d,1+d),(1-d,1+d), **kwargs)
plt.show()

这篇关于带有断裂轴和交错色条的直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆