如何将Matplotlib轴的刻度从0-1更改为Sin函数

时间:2019-05-27 19:11:46

标签: python matplotlib

我正在尝试将图上的轴从0缩放到1,但要遵循该区间内sin函数的进展。 我需要执行此操作以获得图形的均匀数据分布。

我尝试使用FuncScale运算符,但无济于事。

import numpy as np
import matplotlib.pyplot as plt
import random as rand

#Define radius and angle
r = np.arange(0,5,0.0001)
a = np.arange(0, np.pi/2 ,(np.pi/100000))#[:-1]
print(len(r))
print(len(a))
#x = r * np.cos(a)
#y = r * np.sin(a)

#Generate random integer list and zip with radii and angles
samp=50000
q = rand.sample(range(samp),samp)
qrzip = zip(r,q)
u = rand.sample(range(samp),samp)
uazip = zip(a,u)

#Turn tuples back into list
qr = list(qrzip)
ua = list(uazip)

# Sort with lambda function
qr.sort(key=lambda x: x[1])
ua.sort(key=lambda x: x[1])

#Form lists of radii and angles in random order
qrr = [qrr[0] for qrr in qr]
uaa = [uaa[0] for uaa in ua]

#Define variables
cos = qrr*np.cos(uaa)
sin = qrr*np.sin(uaa)

plt.plot(cos, sin,'g,')
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.gca().set_aspect('equal', adjustable='box')
plt.draw()

该函数以普通整数比例绘制,但我希望它以sin(0,1)比例绘制

0 个答案:

没有答案