I am attempting to plot an ellipse surrounding scattered data points, but when the pyplot displays my plot only the data points are showing up and ellipse isn't. Do I need to install the patch somehow?
Here is my code:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as pp
import numpy as np
from matplotlib import cm
import pandas as pd
from matplotlib.patches import Ellipse
data_to_plot = pd.read_csv("positions.csv", sep = ",", index_col=False)
xs = data_to_plot['x']
ys = data_to_plot['y']
zs = data_to_plot['z']
covxy = np.cov(xs, ys)
lambda_xy, vxy = np.linalg.eig(covxy)
lambda_xy = np.sqrt(lambda_xy)
ax1 = pp.subplot(221)
for j in xrange(1, 4):
ell = Ellipse(xy=(xav, yav),
width=lambda_xy[0]*j*2, height=lambda_xy[1]*j*2,
angle=-np.rad2deg(np.arccos(vxy[0, 0])))
ell.set_facecolor('none')
ax1.add_artist(ell)
ax1.set_xlabel("x distance from the sun / AU")
ax1.set_ylabel("y distance from the sun / AU")
pp.scatter(xs, ys)
pp.xlim(xav-0.001,xav+0.0013)
pp.ylim(yav-0.001,yav+0.001)
ell.set_facecolor('none')
seems counterproductive. If the intention is to show the ellipse, it should not have 'none'
as color. Or it should have at least an edgecolor being set, eg
ell.set_edgecolor("limegreen")
Or consider giving the colors as arguments to the ellipse
Ellipse(..., fc="none", ec="limegreen")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.