简体   繁体   English

如何使用 matplotlib 在圆形条形图上绘制矩形

[英]How to draw a rectangle on a circular barplot using matplotlib

I am trying to draw a rectangle on a circular barplot generated by matplotlib.我正在尝试在 matplotlib 生成的圆形条形图上绘制一个矩形。 There are numerous tutorials online but they only cover regular 2D plots, the same code creates circles in circular bar plots rather than rectangles.网上有很多教程,但它们只涵盖常规的 2D 图,相同的代码在圆形条形图中创建圆圈而不是矩形。

This is what I am trying to programmatically generate:这就是我试图以编程方式生成的内容:

在此处输入图像描述

Here's one way:这是一种方法:

import matplotlib.patches as patches

fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
axin = ax.inset_axes([0.0, 0.0, 1, 1])
axin.axis('off')
rect = patches.Rectangle((0.5, 0.25), 0.5, 0.25, linewidth=2, edgecolor='r', facecolor='none')
axin.add_patch(rect)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM