python 条形图图注怎么集中_在python中创建圆形条形图

1586010002-jmsa.png

I would be interested in using a circular barplot visualisation for my project, and have no idea whatsoever how to produce it in Python. Please see an example of what I mean for "circular barplot" below. Data would come in form of a pandas series - dummy example below to vaguely reflect the plot:

A 33

B 62

C 56

D 70

Any idea?

YoXRG.png

解决方案

That is just an horizontal bar plot in polar projection. Matplotlib defaults will make it look a bit different.

ax = plt.subplot(projection='polar')

ax.barh(0, math.radians(150))

ax.barh(1, math.radians(300))

ax.barh(2, math.radians(270))

ax.barh(3, math.radians(320))

XRT8q.png

But it can be tuned:

Use set_theta_zero_location() to make the bars start at North.

Use set_theta_direction() to make the bars go clockwise.

Use set_rlabel_position() to move the radial labels.

Use set_thetagrids() and set_rgrids() to set the ticks and labels.

The result is very similar:

ax.set_theta_zero_location('N')

ax.set_theta_direction(-1)

ax.set_rlabel_position(0)

ax.set_thetagrids([0, 96, 192, 288], labels=[0, 20, 40, 60])

ax.set_rgrids([0, 1, 2, 3], labels=['a', 'b', 'c', 'd'])

S7nBL.png

There must be a way to move the radial labels to the left of the bars but I could not find it.

PS A more concise and maybe faster way:

ax.barh([0, 1, 2, 3], np.radians([150, 300, 270, 320]),

color=plt.rcParams['axes.prop_cycle'].by_key()['color'])

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值