为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

qq_花开花谢_0 2021-11-16 15:47:07
该图表几乎看起来不错,但可能不是在 matplotlib 中对其进行建模的方式。如何有两个水平条在 x 点处延伸到垂直线的左侧和右侧,以显示两个数据集的变化,例如 SDR 从 0.7 到 0.25。目前,我用'$-$'标记将东西拼凑在一起,使图例错位,我无法正确放置。如果我更改 figsize,则标记开始与 x 点处的垂直条不对齐,例如 SDR。如何对这种图表进行探测建模?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#cordxax.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()
查看完整描述

2 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

或者,您可以使用barh在这种情况下更直观的水平条形图。这里的关键参数是left将水平条形图向左/向右移动。


下面是一个完整的答案:


import numpy as np

import matplotlib.pyplot as plt


np.random.seed(2)

layer0 = np.random.random(10)


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

n = 10

width = 0.5

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


ax.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()

//img1.sycdn.imooc.com//6193656200014a3305250256.jpg

查看完整回答
反对 回复 2021-11-16
?
一只斗牛犬

TA贡献1784条经验 获得超2个赞

到目前为止,我还没有想到底部偏移的条形图,这似乎没问题:


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#cordx

height=0.03

width=0.8

ax.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)

//img1.sycdn.imooc.com//619365720001e7d705250179.jpg

查看完整回答
反对 回复 2021-11-16
  • 2 回答
  • 0 关注
  • 154 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信