Home > Blockchain >  .add_patch() base file issue
.add_patch() base file issue

Time:06-28

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

CodePudding user response:

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
)
  • Related