如何制作只有高度指示器而不显示完整条形的条形图?

该图表几乎看起来不错,但可能不是在 matplotlib 中对其进行建模的方式。如何有两个水平条在 x 点处延伸到垂直线的左侧和右侧,以显示两个数据集的变化,例如 SDR 从 0.7 到 0.25。

目前,我用'$-$'标记将东西拼凑在一起,使图例错位,我无法正确放置。如果我更改 figsize,则标记开始与 x 点处的垂直条不对齐,例如 SDR。

如何对这种图表进行探测建模?

http://img3.mukewang.com/619365520001037803590180.jpg

layer0 = np.random.random(10)


fig, ax = plt.subplots(1,1, figsize=(15/2,1.5*2.5),)

ind = np.arange(10, dtype=np.float64)*1#cordx


ax.plot(ind[0::2]+0.05, layer0[0::2]-0.04, ls='None', marker='$-$', markersize=40)

ax.plot(ind[1::2]-0.15, layer0[1::2]-0.04, ls='None', marker='$-$', markersize=40)

ax.set_ylim(0,1.05) 

ax.set_yticks(np.arange(0, 1.1, step=0.1))

ax.set_xticks(ind[0::2]+0.5)

ax.set_xticklabels( ('SDR', 'SSR', 'SCR', 'RCR', 'GUR') )

plt.grid(b=True)

plt.grid(color='black', which='major', axis='y', linestyle='--', lw=0.2)

plt.show()


qq_花开花谢_0
浏览 155回答 2
2回答

宝慕林4294392

或者,您可以使用barh在这种情况下更直观的水平条形图。这里的关键参数是left将水平条形图向左/向右移动。下面是一个完整的答案:import numpy as npimport matplotlib.pyplot as pltnp.random.seed(2)layer0 = np.random.random(10)fig, ax = plt.subplots(1,1, figsize=(15/2,1.5*2.5),)n = 10width = 0.5ind = np.arange(n, dtype=np.float64)*1#cordxax.barh(layer0[0::2], [width]*int(n/2), height=0.01, left = ind[0::2])ax.barh(layer0[1::2], [width]*int(n/2), height=0.01, left = ind[0::2]+width)ax.set_ylim(0,1.05) ax.set_yticks(np.arange(0, 1.1, step=0.1))ax.set_xticks(ind[0::2]+0.5)ax.set_xticklabels( ('SDR', 'SSR', 'SCR', 'RCR', 'GUR') )plt.grid(b=True)plt.grid(color='black', which='major', axis='y', linestyle='--', lw=0.2)plt.show()

一只斗牛犬

到目前为止,我还没有想到底部偏移的条形图,这似乎没问题:layer0 = np.random.random(10)fig, ax = plt.subplots(1,1, figsize=(15/1.3,1.5*2.5),)# sharey=True)ind = np.arange(10, dtype=np.float64)*1#cordxheight=0.03width=0.8ax.bar(ind[0::2]-width/2, height, width=width, bottom=layer0[0::2]-height)ax.bar(ind[0::2]+width/2, height, width=width, bottom=layer0[1::2]-height)ax.set_ylim(-0.,1.05)plt.grid(color='black', which='major', axis='x', linestyle='-', lw=0.8)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python