Home > OS >  Can't draw circle with right proportions Matplotlib Python
Can't draw circle with right proportions Matplotlib Python

Time:11-22

I want to draw Circle on my plot. For this purpose I decided to use patch.Circle class from matplotlib. Cirlce object uses radius argument to set a radius of a circle, but if the axes ratio is not 1 (see my plot), how to draw circle with right proportions? My code for drawing circle is:

rect = patches.Circle(xy=(9, yaxes),radius= 2, linewidth=3, edgecolor='r', facecolor='red',alpha=0.5)
ax.add_patch(rect)

yaxes is equal 206 in this example (because I wanted to draw it upper left coner). Here is a picture I got using this code: enter image description here

But I want something like this: enter image description here

CodePudding user response:

The issue seems to be that your X (passed to xy=) is not always the same as your Y, thus the oval instead of a perfect circle.

CodePudding user response:

You could use drawing a circle with radius in x coordinates

Some remarks about drawing the ellipse:

  • this will only work for linear coordinates, not e.g. for logscale or polar coordinates
  • the code supposes nor the axis limits nor the axis position will change afterwards, as these will distort the aspect ratio
  • Related