 # Aspect ratio of a circle

Hi,

I am using the Qt4 based back engine for displaying a 2D plot in a widget. The plot typically contains lots of line plots. Suppose I add a CirclePolygon to the plot like this:

circle = CirclePolygon((x,y), radius=0.04, edgecolor='black', facecolor='red', zorder=1)

Then when I start to zoom in the window the aspect ratio of the circle is not preserved (it appears like an ellipse). If you plot a line with points, displaying its points using circles, these circles do have their aspect ratio (and size) preserved. There must be some approach for achieving the same effect for a manually added circle.

Any help is appreciated,

Best regards,

···

--
+--------------------------------------------------------------+

+-------------------------------+------------------------------+

QuantumWise A/S | phone: +45-29716388 |
Lers� Parkall� 107 | www: www.quantumwise.com |
DK-2100 Copenhagen �, Denmark | email: mads.ipsen@...287... |

+-------------------------------+------------------------------+

Did you add axis=‘equal’ to you axes command?

``````e.g. ax = fig.add_subplot(111, aspect='equal')

``````

-Aman

···

On Wed, Mar 9, 2011 at 6:07 AM, Mads Ipsen <madsipsen@…287…> wrote:

Hi,

I am using the Qt4 based back engine for displaying a 2D plot in a

widget. The plot typically contains lots of line plots. Suppose I add a

CirclePolygon to the plot like this:

facecolor=‘red’, zorder=1)

Then when I start to zoom in the window the aspect ratio of the circle

is not preserved (it appears like an ellipse). If you plot a line with

points, displaying its points using circles, these circles do have their

aspect ratio (and size) preserved. There must be some approach for

achieving the same effect for a manually added circle.

Any help is appreciated,

Best regards,

±-------------------------------------------------------------+

±------------------------------±-----------------------------+

QuantumWise A/S | phone: +45-29716388 |

Lersø Parkallé 107 | www: www.quantumwise.com |

DK-2100 Copenhagen Ø, Denmark | email: mads.ipsen@…287… |

±------------------------------±-----------------------------+

Colocation vs. Managed Hosting

A question and answer guide to determining the best fit

for your organization - today and in the future.

http://p.sf.net/sfu/internap-sfd2d

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I tried that, but that will make the entire plot look very strange
if xlim = [0;100] and ylim=[-1:1].

``````What I really want to do is add a scale free aspect ratio correct
``````

circle to the plot. Just like the circles that appear on a scatter
plot.

``````Best regards,

``````
···
``````-- +--------------------------------------------------------------+
| Mads Ipsen, Scientific developer |
+-------------------------------+------------------------------+
| QuantumWise A/S | phone: +45-29716388 |
| Lersø Parkallé 107 | www: |
| DK-2100 Copenhagen Ø, Denmark | email: |
+-------------------------------+------------------------------+
``````

Could you provide some sample code that recreates the problem (and shows what you’re trying to accomplish)?

···

On Wed, Mar 9, 2011 at 8:58 AM, Mads Ipsen <madsipsen@…287…> wrote:

``````I tried that, but that will make the entire plot look very strange
``````

if xlim = [0;100] and ylim=[-1:1].

``````What I really want to do is add a scale free aspect ratio correct
``````

circle to the plot. Just like the circles that appear on a scatter
plot.

``````Best regards,

``````
``````On 2011-03-09 14:44, Aman Thakral wrote:
``````

``````  Did you add axis='equal' to you axes command?
``````
``````e.g. ax = fig.add_subplot(111, aspect='equal')
``````

-Aman

``````    On Wed, Mar 9, 2011 at 6:07 AM, Mads Ipsen <madsipsen@...287...> > >         wrote:
``````

Hi,

``````      I am using the Qt4 based back engine for displaying a 2D plot
``````

in a

``````      widget. The plot typically contains lots of line plots.
``````

``````      CirclePolygon to the plot like this:

facecolor='red', zorder=1)

Then when I start to zoom in the window the aspect ratio of
``````

the circle

``````      is not preserved (it appears like an ellipse). If you plot a
``````

line with

``````      points, displaying its points using circles, these circles do
``````

have their

``````      aspect ratio (and size) preserved. There must be some approach
``````

for

``````      achieving the same effect for a manually added circle.

Any help is appreciated,

Best regards,

--
``````

±-------------------------------------------------------------+

``````      > Mads Ipsen, Scientific developer
``````

±------------------------------±-----------------------------+

``````      > QuantumWise A/S               | phone:          +45-29716388
``````
``````      > Lersø Parkallé 107            | www:     [www.quantumwise.com](http://www.quantumwise.com) |

> DK-2100 Copenhagen Ø, Denmark | email:  mads.ipsen@...287...
>
``````

±------------------------------±-----------------------------+

``````      Colocation vs. Managed Hosting

A question and answer guide to determining the best fit

for your organization - today and in the future.

[http://p.sf.net/sfu/internap-sfd2d](http://p.sf.net/sfu/internap-sfd2d)

_______________________________________________

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

[https://lists.sourceforge.net/lists/listinfo/matplotlib-users](https://lists.sourceforge.net/lists/listinfo/matplotlib-users)
``````
``````-- +--------------------------------------------------------------+
> Mads Ipsen, Scientific developer |
+-------------------------------+------------------------------+
> QuantumWise A/S | phone: +45-29716388 |
> Lersø Parkallé 107 | www: [www.quantumwise.com](http://www.quantumwise.com) |
> DK-2100 Copenhagen Ø, Denmark | email: mads.ipsen@...287... |
+-------------------------------+------------------------------+
``````

Here is a script (below).

``````I want the blue circle to appear as a circle with a 1:1 aspect
``````

ratio, making it look like a circle and not an ellipse. Just like
the scale free circles making up the curve of the damped
oscillationsn also shown in the plot.

``````Preferably, the circle should also be scale free making it have the
``````

same size no-matter how much the plot has been zoomed.

``````Best regards,

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import CirclePolygon

x = np.arange(0, 10, 0.1)
y = np.exp(-x/2.) * np.sin(2*np.pi*x)

fig = plt.figure()
ax.plot(x, y, 'ro-', zorder=0)
ax.set_xlim(0, 10)
ax.set_ylim(-1, 1)

# I want this circle to appear as a circle

plt.show()
``````
···
``````-- +--------------------------------------------------------------+
| Mads Ipsen, Scientific developer |
+-------------------------------+------------------------------+
| QuantumWise A/S | phone: +45-29716388 |
| Lersø Parkallé 107 | www: |
| DK-2100 Copenhagen Ø, Denmark | email: |
+-------------------------------+------------------------------+
``````

You could use a big marker in a scatter plot; the default marker style is a circle. For example: ···

On Wed, Mar 9, 2011 at 8:15 AM, Mads Ipsen <madsipsen@…120…287…> wrote:

Here is a script (below).

``````I want the blue circle to appear as a circle with a 1:1 aspect
``````

ratio, making it look like a circle and not an ellipse. Just like
the scale free circles making up the curve of the damped
oscillationsn also shown in the plot.

``````Preferably, the circle should also be scale free making it have the
``````

same size no-matter how much the plot has been zoomed.

import numpy as np

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

x = np.arange(0, 10, 0.1)
y = np.exp(-x/2.) * np.sin(2np.pix)

fig = plt.figure()
ax.plot(x, y, ‘ro-’, zorder=0)

ax.set_xlim(0, 10)
ax.set_ylim(-1, 1)

# I want this circle to appear as a circle

plt.scatter([7.5],[0.0], s=800, edgecolor=‘k’, facecolor=‘b’, alpha=0.5)

plt.show()

Warren

``````Best regards,

import numpy as np

import matplotlib.pyplot as plt

from matplotlib.patches import CirclePolygon

x = np.arange(0, 10, 0.1)

y = np.exp(-x/2.) * np.sin(2*np.pi*x)

fig = plt.figure()

ax.plot(x, y, 'ro-', zorder=0)

ax.set_xlim(0, 10)

ax.set_ylim(-1, 1)

# I want this circle to appear as a circle

plt.show()
``````
``````On 2011-03-09 15:00, Aman Thakral wrote:
``````
``````  Could you provide some sample code that recreates the
``````

problem (and shows what you’re trying to accomplish)?

``````    On Wed, Mar 9, 2011 at 8:58 AM, Mads > > Ipsen <madsipsen@...287...> > >         wrote:
``````
``````        I tried that, but that
``````

will make the entire plot look very strange if xlim =
[0;100] and ylim=[-1:1].

``````        What I really want to do is add a scale free aspect ratio
``````

correct circle to the plot. Just like the circles that
appear on a scatter plot.

``````        Best regards,

On 2011-03-09 14:44, Aman Thakral wrote:
``````

``````              Did you add axis='equal' to you axes command?
``````
``````e.g. ax = fig.add_subplot(111, aspect='equal')
``````

-Aman

``````                On Wed, Mar 9, 2011 at 6:07 AM, Mads Ipsen <madsipsen@...287...> > > > >                     wrote:
``````

Hi,

``````                  I am using the Qt4 based back engine for
``````

displaying a 2D plot in a

``````                  widget. The plot typically contains lots of line
``````

``````                  CirclePolygon to the plot like this:

``````

edgecolor=‘black’,

``````                  facecolor='red', zorder=1)

Then when I start to zoom in the window the aspect
``````

ratio of the circle

``````                  is not preserved (it appears like an ellipse). If
``````

you plot a line with

``````                  points, displaying its points using circles, these
``````

circles do have their

``````                  aspect ratio (and size) preserved. There must be
``````

some approach for

``````                  achieving the same effect for a manually added
``````

circle.

``````                  Any help is appreciated,

Best regards,

--
``````

±-------------------------------------------------------------+

``````                  > Mads Ipsen, Scientific developer
>
``````

±------------------------------±-----------------------------+

``````                  > QuantumWise A/S               | phone:
``````

+45-29716388 |

``````                  > Lersø Parkallé 107            | www:     [www.quantumwise.com](http://www.quantumwise.com) |

> DK-2100 Copenhagen Ø, Denmark | email:  mads.ipsen@...985..... |
``````

±------------------------------±-----------------------------+

``````                  Colocation vs. Managed Hosting

A question and answer guide to determining the
``````

best fit

``````                  for your organization - today and in the future.

[http://p.sf.net/sfu/internap-sfd2d](http://p.sf.net/sfu/internap-sfd2d)

_______________________________________________

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

[https://lists.sourceforge.net/lists/listinfo/matplotlib-users](https://lists.sourceforge.net/lists/listinfo/matplotlib-users)
``````
``````-- +--------------------------------------------------------------+
> Mads Ipsen, Scientific developer |
+-------------------------------+------------------------------+
> QuantumWise A/S | phone: +45-29716388 |
> Lersø Parkallé 107 | www: [www.quantumwise.com](http://www.quantumwise.com) |
> DK-2100 Copenhagen Ø, Denmark | email: mads.ipsen@...287... |
+-------------------------------+------------------------------+
``````
``````-- +--------------------------------------------------------------+
> Mads Ipsen, Scientific developer |
+-------------------------------+------------------------------+
> QuantumWise A/S | phone: +45-29716388 |
> Lersø Parkallé 107 | www: [www.quantumwise.com](http://www.quantumwise.com) |
> DK-2100 Copenhagen Ø, Denmark | email: mads.ipsen@...287... |
+-------------------------------+------------------------------+
``````

Colocation vs. Managed Hosting

A question and answer guide to determining the best fit

for your organization - today and in the future.

http://p.sf.net/sfu/internap-sfd2d

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

The way this is done is tricky. The transform object assigned to the
circles in plot() and scatter() are different than the default when
you make a circle polygon yourself. The easiest way to get them is to
just simply use scatter() and pass in your own size value.

I hope that helps!
Ben Root

···

Hi,

I am using the Qt4 based back engine for displaying a 2D plot in a
widget. The plot typically contains lots of line plots. Suppose I add a
CirclePolygon to the plot like this:

facecolor='red', zorder=1)

Then when I start to zoom in the window the aspect ratio of the circle
is not preserved (it appears like an ellipse). If you plot a line with
points, displaying its points using circles, these circles do have their
aspect ratio (and size) preserved. There must be some approach for
achieving the same effect for a manually added circle.

Any help is appreciated,

Best regards,

Thanks.

The intention is to make the added circle dragable by the mouse by listening to mouse press, move, and release.

That means that I have to modify the data of the added scatter data. I believe that the axes.scatter() method returns a matplotlib.collections.CircleCollection object. How do I change the position of the circles (one circle) contained in this object?

···

On 2011-03-09 15:28, Benjamin Root wrote:

Hi,

I am using the Qt4 based back engine for displaying a 2D plot in a
widget. The plot typically contains lots of line plots. Suppose I add a
CirclePolygon to the plot like this:

facecolor='red', zorder=1)

Then when I start to zoom in the window the aspect ratio of the circle
is not preserved (it appears like an ellipse). If you plot a line with
points, displaying its points using circles, these circles do have their
aspect ratio (and size) preserved. There must be some approach for
achieving the same effect for a manually added circle.

Any help is appreciated,

Best regards,

The way this is done is tricky. The transform object assigned to the
circles in plot() and scatter() are different than the default when
you make a circle polygon yourself. The easiest way to get them is to
just simply use scatter() and pass in your own size value.

I hope that helps!
Ben Root

--
+--------------------------------------------------------------+

+-------------------------------+------------------------------+

QuantumWise A/S | phone: +45-29716388 |
Lers� Parkall� 107 | www: www.quantumwise.com |
DK-2100 Copenhagen �, Denmark | email: mads.ipsen@...287... |

+-------------------------------+------------------------------+

You may use offsetbox module.

Here is an complete example. Note that the circle always has a size of
25 point and also is draggable,

Regards,

-JJ

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import CirclePolygon, Circle

x = np.arange(0, 10, 0.1)
y = np.exp(-x/2.) * np.sin(2*np.pi*x)

fig = plt.figure()
ax.plot(x, y, 'ro-', zorder=0)
ax.set_xlim(0, 10)
ax.set_ylim(-1, 1)

# I want this circle to appear as a circle
from matplotlib.offsetbox import DrawingArea, AnnotationBbox,
DraggableAnnotation
circle_radius = 25 # in points

an1 = AnnotationBbox(da,
xy=(7.5, 0.0), xycoords='data',
annotation_clip=False,
box_alignment=(0.5, 0.5),
)

class DraggableAnn(DraggableAnnotation):
def finalize_offset(self):
loc_in_canvas = self.annotation.xytext
self.annotation.textcoords = "data"
pos_data =
self.annotation.axes.transData.inverted().transform_point(loc_in_canvas)
self.annotation.xytext = tuple(pos_data)

drag1 = DraggableAnn(an1, use_blit=False)

plt.show()

···

On Wed, Mar 9, 2011 at 11:15 PM, Mads Ipsen <madsipsen@...287...> wrote:

I want the blue circle to appear as a circle with a 1:1 aspect ratio, making
it look like a circle and not an ellipse. Just like the scale free circles
making up the curve of the damped oscillationsn also shown in the plot.

Preferably, the circle should also be scale free making it have the same
size no-matter how much the plot has been zoomed.