.add_patch()基本文件问题



在我编写的代码中,.add_patch()给出错误。在过去的5天里,我一直在试图弄清楚这一点,但没有成功。当我将它单独用于一个椭圆而不是将它与另一个椭圆结合使用时,相同的调用正在工作。请调查一下!!

# Importing Necessary Libraries
import pandas as pd
import numpy as np
import random as rd
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.style as stl
xys = [[10,125],[100,26],[25,66],[67,1],[74,10]]
xys=np.array(xys)
mean = np.mean(xys,0)
stdDev = np.std(xys,0)
ellipse = patches.Ellipse(mean[0],mean[1],stdDev[0]*2,stdDev[1]*2)
fig, graph=plt.subplots()
graph.scatter(xys[:,0],xys[:,1])
graph.scatter(mean[0],mean[1])
graph.add_patch(ellipse)

这是我在终端上运行

文件时得到的结果

查看patches.Ellipse的文档

In [ ]: patches.Ellipse?
Init signature: patches.Ellipse(xy, width, height, angle=0, **kwargs)
Docstring:      A scale-free ellipse.
Init docstring:
Parameters
----------
xy : (float, float)
xy coordinates of ellipse centre.
width : float
Total length (diameter) of horizontal axis.
height : float
Total length (diameter) of vertical axis.
angle : float, default: 0
Rotation in degrees anti-clockwise.

所以这是:

ellipse = patches.Ellipse(
xy=(mean[0], mean[1]),
width=std[0] * 2,
height=std[1] * 2
)

相关内容

  • 没有找到相关文章

最新更新