.add_patch()基本文件问题

发布于 2025-02-11 03:17:03 字数 733 浏览 1 评论 0原文

在我编写的代码中,.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)

这是我在运行文件时在终端上获得的结果

In the code I wrote, .add_patch() is giving error. Have been trying to figure this out for past 5 days but couldn't do so.
The same call is working when I use it separately for just an ellipse instead of combining it with another one.
Kindly look into this!!

# 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)

This is the result I am getting on the terminal when I am running the file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼前雾蒙蒙 2025-02-18 03:17:03

查看

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
)

Look at the documentation for 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.

So this is:

ellipse = patches.Ellipse(
    xy=(mean[0], mean[1]),
    width=std[0] * 2,
    height=std[1] * 2
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文