1

I'm new to 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:

enter image description here

Instead of the symmetric red circle is it possible to make a custom shape handwriting style? Something like this one:

enter image description here

I have tried to use the AnnotationBbox insted of ax.scatter:

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:

enter image description here

8
  • 2
    Store it as a png with transparency and plot it over your curve? Commented Jan 28, 2022 at 19:02
  • @Mr.T That could work, yes. Do you think programming way is too complicated? Or it is not possible with matplotlib? Commented Jan 28, 2022 at 19:06
  • Or perhaps save the graph plot in pdf/png and then with another software (e.g.: inkscape) you could add it manually and adjust it in and easier way Commented Jan 28, 2022 at 19:10
  • See for instance here: stackoverflow.com/q/22566284/8881141 Commented Jan 28, 2022 at 19:11
  • 1
    You could use the with construction: with plt.xkcd(scale=10): ax.add_patch(Arc((3, 2), 0.3, 0.3, 0, 271, 270, edgecolor='#ff575a', lw=2, facecolor='none', alpha=0.5, zorder=1)) Commented Jan 28, 2022 at 20:19

1 Answer 1

1

The following example code uses the xkcd style to draw a wiggly arc. You might need to experiment with the parameters for the best fit with your 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()

drawing a wiggly arc, xkcd style

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.