绘制椭圆但椭圆的图形未显示

时间:2018-03-02 14:28:28

标签: python python-2.7 matplotlib

我试图绘制一个围绕散乱数据点的椭圆,但是当pyplot显示我的绘图时,只显示数据点而椭圆不显示。我需要以某种方式安装补丁吗?

这是我的代码:

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)

1 个答案:

答案 0 :(得分:1)

ell.set_facecolor('none')似乎适得其反。如果打算显示椭圆,则不应将'none'作为颜色。或者它应该至少设置一个edgecolor,例如

ell.set_edgecolor("limegreen")

或者考虑将颜色作为椭圆的参数

Ellipse(..., fc="none", ec="limegreen")