Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

matplotlib - How to generate the plot of custom shape using numpy or other python libraries

I am interested in generating some random plots for data-based classification problems. These plots are generated inside the x-y plane. The maximum value of x and y is one. The main purpose of this is to generate a dummy dataset for a classification algorithm. The below figure is an example of the expected plot. Other than this I am also written a small code. expected out come

import numpy as np 
import matplotlib.pyplot as plt


x=np.linspace(0.15, 0.95, 100, endpoint = True) 
x= x.reshape(100, 1)
noise =np.random.normal(0,0.1, [100,1])*0.25
x=x+noise;
s=(100,1);
y=0.5*(np.ones(s));
xy=np.hstack((x,y));
plt.plot(x,y)


x1 = np.linspace(0.15*np.pi, 0.95*np.pi, 100)
x1max=max(x1)
x1=x1/x1max;
y1 = 2*np.cosh(x1/2)
y1max=max(y1)
y1=y1/y1max;
plt.plot(x1, y1)



x2 = np.linspace(0.15*np.pi, 2*np.pi, 100)
x2max=max(x2)
x2=x2/x2max;
y2 = np.sin(x2)
y2max=max(y2)
y2=y2/y2max;
plt.plot(x2, y2)


def cart2pol(a, b):
    rho = np.sqrt(a**2 +b**2)
    theta = np.arctan2(b,a)
    return(rho, theta)

def pol2cart(rho, phi):
    a = rho * np.cos(theta)
    b = rho * np.sin(theta)
    return(a, b)

[x3,y3]=cart2pol(x,y)
x3max=max(x3)
x3=x3/x2max;
y3max=max(y3)
y3=y3/y3max;
plt.plot(x3, y3)



[x4,y4]=cart2pol(x1,y1)
x4max=max(x4)
x4=x4/x4max;
y4max=max(y4)
y4=y4/y4max;
plt.plot(x4, y4)
question from:https://stackoverflow.com/questions/65950310/how-to-generate-the-plot-of-custom-shape-using-numpy-or-other-python-libraries

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...