如何从数据框中的三列绘制轮廓图? (其他SO答案无效)

时间:2019-08-12 01:19:04

标签: python matplotlib scikit-learn

我想基于满足条件的可能性创建轮廓图(图)。到目前为止,我有三列相等的长度-土壤饱和度(X),风暴强度(Y)和(Z)满足条件的概率(即0-1)

我的X和Y数据具有不同数量的唯一值,因此每个X值都有许多相应的Y值,从这些值可以生成典型散点图中的点。我希望在位置(X,Y)处具有概率的轮廓,希望可以将每个轮廓表示为决策边界,其中1的决策要高于该概率值(例如0.4、0.5、0.6等)。 )。

到目前为止,我已经尝试了许多选项,其中大多数以np.meshgrid开头。我将在下面发布一些示例图。无论如何,我可以将其清理为每个概率边界只有一行吗?

这是我要从中绘制轮廓的示例散点图:

plt.figure(figsize=(18,5))
plt.scatter(sat_depth_test.loc[:,'soil sat'],sat_depth_test.loc[:,'storm depth'],c=probas[:,1],cmap='YlOrRd')
plt.colorbar()
plt.title('Prediction Boundary for Ksat = 0.00001, all other Base Case Parameterizations')
plt.xlabel('Antecedent Soil Saturation')
plt.ylabel('Storm Storm Depth (mm)')
plt.yscale('log')
plt.ylim([5,150])

scatterplot

我也做了类似的事情,但是没有一行显示决策边界:

triang = tri.Triangulation(sat, storm)
interpolator = tri.LinearTriInterpolator(triang, probdf['Prob'])
X,Y = np.meshgrid(sat,storm)
Z = interpolator(X, Y)
plt.figure(figsize=(15,5))
plt.contour(X,Y,Z)
plt.colorbar()
plt.title('Prediction Boundary for Ksat = 0.00001, all other Base Case Parameterizations')
plt.xlabel('Antecedent Soil Saturation')
plt.ylabel('Storm Storm Depth (mm)')
plt.yscale('log')
plt.ylim([5,150])

contour plot

我只是觉得有点卡在这里。理想情况下,我希望用单行显示每个0.05或0.10概率间隔的轮廓,以代替散点图。

这类似于此,但仍然更干净:

cleaner contour

理想情况下,我想要这样的东西:(从https://jakevdp.github.io/PythonDataScienceHandbook/04.04-density-and-contour-plots.html借来的)

ideal plot

我也很抱歉没有在此处放置实际情节。这是我关于SO的第一个问题,我很难找出如何将其包括在内。

谢谢!

0 个答案:

没有答案