首先,我想要生成一个绘图,通过平均数据与目标的接近程度来着色。 (真正的程序是试图学习权重的机器学习算法)。我想为最终图中的每个数据点生成一个直方图,但我似乎无法独立生成这些图。任何帮助将不胜感激。
import matplotlib.pyplot as plt
import numpy as np
def generateData(goal):
x=[_ for _ in range(20)]
y=[10+np.random.exponential()*5 for _ in range(100)]
return x,y
def drawHistogram(data,nBins):
plt.figure(2)
plt.hist(diffs,nBins)
plt.draw()
plt.show()
sweep=np.linspace(10,20,4)
for goal in sweep:
for gw2 in sweep:
diffs=[]
for i in range(10):
data=generateData(goal)
diffs.append(goal-np.mean(data[1]))
#generate plot
plt.figure(1)
clr=(abs(np.mean(diffs))/goal,0,0)
plt.plot([goal], [gw2], marker="s", mew='1', ms='35', color=clr)
drawHistogram(diffs,5) ##Comment this line out to see what the final graph should look like
plt.figure(1)
plt.draw()
plt.show()
答案 0 :(得分:0)
这会产生17个单独的直方图和1个带红色方块的最终图形。
Green Tomatoes