简体   繁体   English

由 Python 中的 matplotlib 绘制圆形手绘样式

[英]Drawing circle hand drawn style by matplotlib in Python

I'm new to matprotlib.我是 matprotlib 的新手。 After plotting a graph I would like to mark a point.绘制图表后,我想标记一个点。 I do this with the following code:我使用以下代码执行此操作:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.scatter(3, 2, s=500, edgecolor='#ff575a', lw=2, facecolor='none', alpha=0.5, zorder=1) #6.5-row['mag']
ax.plot([1, 2, 3, 4], [1, 4, 2, 3])

The output: output:

在此处输入图像描述

Instead of the symmetric red circle is it possible to make a custom shape handwriting style?代替对称的红色圆圈,是否可以制作自定义形状的手写样式? Something like this one:像这样的东西:

在此处输入图像描述

I have tried to use the AnnotationBbox insted of ax.scatter:我尝试使用 ax.scatter 的AnnotationBbox

ab = AnnotationBbox(OffsetImage(plt.imread('circle.png'), 
    zoom=0.2), (3, 2), frameon=False)

But that make the picture bad with some pixels of the circle missing, so it is not that sharp as the original png:但这会使图片变得很糟糕,缺少一些圆圈的像素,所以它不像原始 png 那样清晰:

在此处输入图像描述

The following example code uses the xkcd style to draw a wiggly arc.以下示例代码使用 xkcd 样式绘制摆动弧。 You might need to experiment with the parameters for the best fit with your plot.您可能需要试验参数以最适合您的 plot。

import matplotlib.pyplot as plt
from matplotlib.patches import Arc

fig, ax = plt.subplots()
ax.scatter(3, 2, s=500, edgecolor='#ff575a', lw=2, facecolor='none', alpha=0.5, zorder=1)  #
ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
with plt.xkcd(scale=10):
    ax.add_patch(Arc((3, 2), 0.3, 0.3, angle=275, theta1=0, theta2=350,
                     edgecolor='#ff575a', lw=2, facecolor='none', alpha=0.5, zorder=1))
plt.show()

画一个摆动的弧线,xkcd 风格

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

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