问题描述
我对三个参数进行了蒙特卡洛反演,现在我正尝试使用Matplotlib将它们绘制成3D图形.这些参数之一( Mo
)的可变性大约在10 ^ 15到10 ^ 20之间,我感兴趣的是绘制好的解(蓝点),其值从10 ^ 17不等到 10^19.我在 z 轴上绘制参数 (Mo
),并且仅将此轴设置为具有重要值范围的对数会很好.我尝试了在其他论坛上看到的不同选项,但情节无法正常工作......也许 Matplotlib 中存在错误,或者我没有正确使用命令.
这是带有线性轴且不限制z轴的原始图形:
如果我尝试将 z 轴设置为对数(通过添加行 ax.set_zscale('log')
),结果缩放似乎无法正常工作,因为每个幂不是等距分布的:
最后,如果我尝试将 z 轴限制在我感兴趣的值范围内(只需添加行 ax.set_zlim3d(1e17,1e19)
),而不是将点切割到此轴上的定义范围,它们似乎脱离了图形:
这是这个图的完整代码.这并不复杂.非常欢迎任何帮助或建议.
fig = figure(2)ax = fig.add_subplot(111, 投影='3d')# 绘图模型:p = ax.scatter(Vr,Dm,Mo,c=misfits,vmin=0.3,vmax=1,s=2,edgecolor='none',marker='o')fig.colorbar(p, ticks=arange(0.3,1+0.1,0.1))#绘图设置:ax.set_xlim3d(0,max(Vr))ax.set_ylim3d(0,max(Dm))ax.set_zlim3d(1e17,1e19)ax.set_zscale('log')ax.set_xlabel("$V_{r}$ [$km/s$]")ax.set_ylabel("$ D_ {max} $ [$ m $]")ax.set_zlabel("$ M_ {o} $ [$ Nm $]")ax.invert_xaxis()喷射()title("运动学参数和$M_{o}$")
这可能与
I performed a Monte Carlo inversion of three parameters, and now I'm trying to plot them in a 3-D figure using Matplotlib. One of those parameters (Mo
) has a variability of values between 10^15 and 10^20 approximately, and I'm interested in plotting the good solutions (blue dots), which vary from 10^17 to 10^19. I'm plotting the parameter (Mo
) in the z-axis, and would be great to set only this axis to be logarithmic with the range of values that matters. I tried different options that I saw in other forums, but the plot does not work properly ... Maybe there is a bug in Matplotlib, or I'm not using the commands correctly.
This is the original figure with linear axes and without restricting the z-axis:
If I try to set the z-axis as logarithmic (by adding the line ax.set_zscale('log')
), the resulting scaling does not seem to work properly, because the ordering of each power is not equally spaced:
And finally, If I try to limit the z-axis to the range of values that I'm interested (by simply adding the line ax.set_zlim3d(1e17,1e19)
), instead of cutting the dots to the defined range in this axis, they seem to scape from the graph:
This is the entire code for this figure in particular. It is not complicated. Any help or advice would be very welcome.
fig = figure(2)
ax = fig.add_subplot(111, projection='3d')
# Plot models:
p = ax.scatter(Vr,Dm,Mo,c=misfits,vmin=0.3,vmax=1,s=2,edgecolor='none',marker='o')
fig.colorbar(p, ticks=arange(0.3,1+0.1,0.1))
# Plot settings:
ax.set_xlim3d(0,max(Vr))
ax.set_ylim3d(0,max(Dm))
ax.set_zlim3d(1e17,1e19)
ax.set_zscale('log')
ax.set_xlabel("$V_{r}$ [$km/s$]")
ax.set_ylabel("$D_{max}$ [$m$]")
ax.set_zlabel("$M_{o}$ [$Nm$]")
ax.invert_xaxis()
jet()
title("Kinematic parameters and $M_{o}$")
This is possibly related to this issue. It's suggested to plot np.log10(z)
instead of z
with log scale. You might want to change your code to:
fig = figure(2)
ax = fig.add_subplot(111, projection='3d')
# Plot models:
p = ax.scatter(Vr,Dm,np.log10(Mo),c=misfits,vmin=0.3,vmax=1,s=2,edgecolor='none',marker='o')
fig.colorbar(p, ticks=arange(0.3,1+0.1,0.1))
# Plot settings:
ax.set_xlim3d(0,max(Vr))
ax.set_ylim3d(0,max(Dm))
ax.set_zlim3d(17,19)
ax.set_xlabel("$V_{r}$ [$km/s$]")
ax.set_ylabel("$D_{max}$ [$m$]")
ax.set_zlabel("$M_{o}$ [$Nm$]")
ax.invert_xaxis()
jet()
title("Kinematic parameters and $M_{o}$")
I also suggest to use tight_layout()
. At least on my machine, axis labels are not shown properly without it. Here's the picture with some fake data:
这篇关于Matplotlib中3-D散点图中的z轴缩放和限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!