Note that there are some explanatory texts on larger screens.

plurals
  1. POellipses with various angles and eccentricities in matplotlib
    primarykey
    data
    text
    <p>I want to make a plot with ellipses as markers. Here is a sample code making one large ellipse that for now is actually a circle. </p> <pre><code>#! /usr/bin/env python3.2 import numpy as np import pylab import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages from matplotlib.patches import Ellipse PlotFileName="test.pdf" pdf = PdfPages(PlotFileName) fig=plt.figure(1) ax1=fig.add_subplot(111) x_lim=3 plt.xlim([0,x_lim]) plt.ylim([0,x_lim]) F=pylab.gcf() DefSize = F.get_size_inches() #These lines have a true angle of 45 degrees, only as a reference: offset_along_x=x_lim-(x_lim/ax_ratio) ax1.plot([offset_along_x/2, x_lim-(offset_along_x/2)], [0, x_lim], "b") ax1.plot([offset_along_x/2, x_lim-(offset_along_x/2)], [x_lim, 0], "b") e=0.0 theta=0 maj_ax=2 min_ax=maj_ax*np.sqrt(1-e**2) xconst=(DefSize[1]/DefSize[0])*np.cos(theta*np.pi/180)-np.sin(theta*np.pi/180) yconst=np.cos(theta*np.pi/180)+(DefSize[1]/DefSize[0])*np.sin(theta*np.pi/180) print("xconstant= {}".format(xconst)) print("yconstant= {}".format(yconst)) ax1.add_artist(Ellipse((x_lim/2, x_lim/2), xconst*maj_ax, yconst*min_ax, angle=theta, facecolor="green", edgecolor="black",zorder=2, alpha=0.5)) pdf.savefig(fig) pdf.close() plt.close() </code></pre> <p>Although in this simplified case, <code>ax1.axis("equal")</code> will give a pure circle, but in my final plot, this command will ruin the whole plot (the scales aren't equal). So I want to make a general purpose ellipse tool without using <code>ax1.axis("equal")</code>. As you see, you can set the eccentricity and the inclination angle of the major axis in this program. </p> <p><strong>The problem:</strong> The problem seems to be that I don't understand how matplotlib rotates its images. If you change the value of <code>theta</code> here to a value other than 0 or 90, the object will no longer be a circle. with <code>ax1.axis("equal")</code> the output is a circle now matter what the value of <code>theta</code> is. So my first problem is this: what should I do to keep the output as a circle while changing <code>theta</code>. I assume that once I fix this, it will also work for an ellipse. Could someone please help me with this? I would really appreciate it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload