【发布时间】:2020-06-29 23:51:04
【问题描述】:
我生成了一条曲线的数据,存储在一个列表中。然后我从这些数据中随机抽取了 1000 个样本。 y 轴显示我的数据,x 轴显示公式输出。到这里为止一切都很好。当我想将我的数据绘制到现有图像上时,问题就开始了。
如您所见,我的 x 轴和 y 轴是对数刻度且低于 1。我已经寻找答案,发现我可以使用 FuncFormatter。但是,它对我不起作用,因为我需要用对数比例绘制我的数据。当我简单地使用plt.xscale('log') 时,该图如下所示:
对数比例的输出图
不带对数刻度的输出图
import matplotlib.pyplot as plt
import numpy as np
#Producing some data and put them in a list named listGercek
xekseni2 = []
data = random.sample(listGercek, 1000)
for teta in data:
olasılık = listGercek.index(teta)/100000
xekseni2.append(olasılık)
im = plt.imread('figure.png')
xmin, xmax, ymin, ymax = (0.001, 1, 0.01, 1)
aspect = im.shape[0] / im.shape[1] * (xmax-xmin)/(ymax-ymin)
plt.imshow(im, zorder=0, extent=[1e-3, 1e0, 1e-2, 1e0], aspect=aspect)
plt.yscale('log')
plt.xscale('log')
plt.xlabel('P')
plt.ylabel(r'$\tau_{c}^{*}$')
plt.plot(xekseni2, data, "ro", marker="o", markersize=1, label="Present Work")
plt.axis([xmin, xmax, ymin, ymax])
plt.legend()
plt.show()
询问的一些数据点:
y:0.09141346037829952, 0.06969760102294438, 0.0473781028644485, 0.059295628198887916, 0.0571418702849134, 0.04050307759274645, 0.08088991113201109, 0.03746878506083184, 0.13583224333004337, 0.03269066677698429, 0.06918929672995293, 0.06040315211901601, 0.05772815718352134, 0.07361582566248871, 0.06212973486945907, 0.03283216378016191, 0.14407484921136313, 0.02266323793619761, 0.04439409523587426, 0.055067724315696655,
x:0.81136, 0.67958, 0.43465, 0.58106, 0.55695, 0.33327, 0.75665, 0.2849, 0.93146, 0.20716, 0.6752, 0.59276, 0.56391, 0.70997, 0.6097, 0.20941, 0.94315, 0.06609, 0.39222, 0.53361,
【问题讨论】:
-
你能添加一些数据吗?例如曲线的 20 个 x,y 位置?
-
确定我可以添加。 @johanCpan>
标签: python matplotlib imread