在matplotlib中带有断轴的分组条形图

时间:2017-12-21 14:06:31

标签: matplotlib bar-chart axis

我正在尝试在matplotlib中创建一个包含错误的分组条形图。 y轴值的范围很高,因此较低的值不足。所以我想绘制具有断开的y轴的图形。 这是我的代码:

import matplotlib.pyplot as plt
import pylab as plt
import numpy as np
import matplotlib as mpl
import pandas as pd
from matplotlib.ticker import NullFormatter
from brokenaxes import brokenaxes
import matplotlib.pyplot as plt

# data to plot
n_groups = 5
plate1 = (2171.30445, 586.0188957, 686.3897089, 1634.08957, 8957.462436)
p1err = (277.796406, 60.74243945, 120.8867298, 232.1931229, 2695.236328)
plate2 = (1924.896604, 626.690557, 430.6515416, 1151.967586, 8040.870352)
p2err = (1672.937164, 194.6229754, 30.06731907, 639.8138954, 903.9350561)


index = np.arange(n_groups)
bar_width = 0.25
opacity = 0.8
error_config = {'ecolor': '0.3'}

rects1 = plt.bar(index, plate1, bar_width,
                 alpha=opacity,
                 color='b',
                 yerr=p1err,
                 capsize=10,
                 error_kw=error_config,
                 label='Plate 1')

rects2 = plt.bar(index + bar_width, plate2, bar_width,
                 alpha=opacity,
                 color='r',
                 yerr=p2err,
                 capsize=10,
                 error_kw=error_config,
                 label='Plate 2')

plt.xticks(index + bar_width, ('C1T25-C1T18', 'C1T25-C1T18c', 'C1NT25-C1T18', 'C1NT25-C1T18c'))

a)我想将y轴分成4000到8000之间。

b)我还想将xticks旋转到45度,以便容纳更多数据。

我将我在excel中制作的最终图表附加为screengrab(注意:这没有断开的y轴) https://www.dropbox.com/s/967jmbnzl4tibkx/Picture1.png?dl=0

0 个答案:

没有答案
相关问题