The plot of the circle on unequal axes with a gun

I would like to build a circle on an autoscaled graph created using pyplot. When i started

ax.get_aspect() 

hoping for a value with which I could manipulate the axes of the ellipse, pyplot returns:

 auto 

which is less useful. What methods would you suggest for constructing a circle on a pipette chart with unequal axes?

+7
source share
3 answers

It really depends on what you want.

The problem with determining the circle in the data coordinates, when the aspect ratio is automatic, is that you can resize the shape (or its window), and the data scale will stretch beautifully. Unfortunately, this also means that your circle is no longer a circle, but an ellipse.

There are several ways to solve this problem. First and foremost, you can fix the aspect ratio, and then put the circle on the graph in the data coordinates:

 import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = plt.axes() ax.set_aspect(1) theta = np.linspace(-np.pi, np.pi, 200) plt.plot(np.sin(theta), np.cos(theta)) plt.show() 

data coords circle

In this case, you can scale and pan, as usual, but the shape will always be around.

If you just want to place a circle on the shape, regardless of the data coordinates, so that panning and zooming of the axes does not affect the position and enlargement of the circle, then you could do something like:

 import matplotlib.patches as mpatches import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = plt.axes() patch = mpatches.Circle((325, 245), 180, alpha=0.5, transform=None) fig.artists.append(patch) plt.show() 

device coordinates circle

This is a pretty advanced mpl, but even so, I think it is readable.

NTN

+3
source

This question is more than one year old, but I also had this question. I needed to add circles to the matplotlib graph, and I would like to indicate the location of the circle on the graph using the data coordinates, and I did not want the radius of the circle to change with pan / zoom (or, even worse, the circle to become an ellipse).

The best and simplest solution I have found is to simply build a single point curve and turn on the circle marker:

 ax.plot(center_x,center_y,'bo',fillstyle='none',markersize=5) 

which gives a beautiful blue circle of a fixed size without filling!

+9
source

Based on @ user3208430, if you want the circle to always be displayed in the same place on the axes (regardless of the data range), you can put it using the axis coordinates using the transformation:

 ax.plot(.94, .94, 'ro', fillstyle='full', markersize=5, transform=ax.transAxes) 

Where x and y are between [0 and 1]. This example places the marker in the upper right corner of the axes.

0
source

All Articles