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

user164863
  • 580
  • 1
  • 12
  • 29
  • 2
    Store it as a png with transparency and plot it over your curve? – Mr. T Jan 28 '22 at 19:02
  • @Mr.T That could work, yes. Do you think programming way is too complicated? Or it is not possible with matplotlib? – user164863 Jan 28 '22 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 – fgoudra Jan 28 '22 at 19:10
  • See for instance here: https://stackoverflow.com/q/22566284/8881141 – Mr. T Jan 28 '22 at 19:11
  • @Mr.T Thank you for the idea. I have checked that and tried with my code. But the .png image gets not that sharp when inserted. I have updated my question with that. – user164863 Jan 28 '22 at 19:44
  • @JohanC can XKCD style be applied to the circle only? – user164863 Jan 28 '22 at 20:16
  • 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))` – JohanC Jan 28 '22 at 20:19
  • @JohanC I this your answer is the most close one, I would accept it if you post it – user164863 Feb 03 '22 at 19:42

1 Answers1

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

JohanC
  • 71,591
  • 8
  • 33
  • 66