三维画图 坐标轴标注和坐标平行的问题
mathematica吧
全部回复
仅看楼主
level 2
data2 = {{446, 651, 14850}, {382, 589, 15673}}
plot2 = ListPointPlot3D[data2,
ColorFunction -> Function[{x, y, z}, Hue[0.03, 1, 1]]]
f[x_, y_] = -11917.525 + 72.999*x - 0.061*x^2 + 32.143*y -
0.028102*(x*y) - 0.015041*y^2
plot1 = Plot3D[f[x, y], {x, 300, 600}, {y, 0, 800},
MeshStyle -> Directive[GrayLevel[0], Dotted], Mesh -> Automatic,
MeshFunctions -> Automatic,
PlotStyle -> Directive[GrayLevel[0], Opacity[0.264`]],
AxesLabel -> {"灌水量Irrigation amount(mm)",
"施肥量 Fertigation(kg.\!\(\*SuperscriptBox[\(hm\), \(-2\)]\))",
"产量Yield(kg.\!\(\*SuperscriptBox[\(hm\), \(-2\)]\))"},
PlotLabel -> Style[a.产量, a.Yield], PlotRange -> {0, 20000},
Boxed -> Dotted]
Show[plot1, plot2]
现在能力只能画成1中的图形,想把1图画成2图那样的形式。
很困惑,希望得到吧主大神帮助,非常感谢。
2020年02月03日 15点02分 1
level 2
【求助】现在遇到两个难题
1. 坐标轴标签和坐标轴平行
2. 拟合方程后 其最大值的95%置信区间该怎么画(图中彩色部分)
恳请吧友各位大神指导,感谢万分!
2020年02月05日 04点02分 2
吧务
level 12
Label方向可以用Rotate调,像这样:
data2 = {{446, 651, 14850}, {382, 589, 15673}};
f[x_, y_] = -11917.525 + 72.999*x - 0.061*x^2 + 32.143*y -
0.028102*(x*y) - 0.015041*y^2;
plot2 = ListPointPlot3D[data2,
ColorFunction -> Function[{x, y, z}, Hue[0.03, 1, 1]]];
plot1 = Plot3D[f[x, y], {x, 300, 600}, {y, 0, 800},
MeshStyle -> Directive[GrayLevel[0], Dotted], Mesh -> Automatic,
MeshFunctions -> Automatic,
PlotStyle -> Directive[GrayLevel[0], Opacity[0.264`]],
PlotRange -> {0, 20000},
PlotLabel -> Style["a.产量,a.Yield", Black, 20, Bold],
Axes -> True, AxesStyle -> Directive[Black, Thick],
TicksStyle -> Directive[Black, 16],
Ticks -> {Range[300, 600, 100], Range[0, 800, 200],
Range[0, 20000, 5000]},
BoxStyle -> Dashed, ImageSize -> 600];
Show[plot1,
AxesLabel -> (MapThread[
Rotate[Text@
Style[#1, 16,
TextAlignment ->
Center], #2] &, {{"灌水量\nIrrigation amount(mm)",
"施肥量\nFertigation/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \
\(-2\)]\))",
"产量\nYield/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \
\(-2\)]\))"}, {-30 \[Degree], 60 \[Degree], 90 \[Degree]}}])]
但是直接出来的效果不太好,label和坐标轴离得太远了,目测的方向也不是特别准,所以用个Manipulate细调一下参数,拖Locator调位置,拖Slider调角度,调好以后再画图导出就行了。
labels = {"灌水量\nIrrigation amount(mm)",
"施肥量\nFertigation/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \(-2\
\)]\))", "产量\nYield/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \
\(-2\)]\))"};
tmp = Manipulate[
plist = p;
\[Alpha]list = {\[Alpha]1, \[Alpha]2, \[Alpha]3};
Graphics[{Inset[plot1, Center, Center, Scaled[.8]],
MapThread[
Rotate[Text[
Style[#1, 16, TextAlignment -> Center],
#2], #
3] &, {labels,
plist, \[Alpha]list}]},
ImageSize -> 600, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}],
{{p, {{-.8, -.8}, {.8, -.8}, {-.8, .8}}}, Locator},
{{\[Alpha]1, -30 \[Degree]}, -\[Pi], \[Pi]},
{{\[Alpha]2, 60 \[Degree]}, -\[Pi], \[Pi]},
{{\[Alpha]3, 90 \[Degree]}, -\[Pi], \[Pi]}
]
(*调好参数以后再运行导出,直接导出图片质量比较差,建议导成pdf*)
Export["Yield.pdf",
Graphics[{Inset[plot1, Center, Center, Scaled[.8]],
MapThread[
Rotate[Text[
Style[#1, 16, TextAlignment -> Center],
#2], #
3] &, {labels,
plist, \[Alpha]list}]},
ImageSize -> 600, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]]
最终结果
2020年02月05日 04点02分 3
厉害厉害大神[大拇指],还有个问题,就是彩色部分是函数最大值的95%置信区间,这个该怎么画出来,我捣鼓了好几天,还是不得其解,望再指教!真的很感激!
2020年02月05日 04点02分
吧务
level 12
fmax = MaxValue[{f[x, y], 300 <= x <= 600 && 0 <= y <= 800}, {x, y}];
\[ScriptCapitalR] = ImplicitRegion[f[x, y] >= 0.95 fmax, {x, y}];
plot1 = Plot3D[f[x, y], {x, 300, 600}, {y, 0, 800},
MeshStyle -> Directive[GrayLevel[0], Dotted], Mesh -> Automatic,
MeshFunctions -> Automatic,
PlotStyle -> Directive[GrayLevel[0], Opacity[0.264`]],
PlotRange -> {0, 20000},
RegionFunction -> Function[{x, y, z}, z < 0.95 fmax],
PlotLabel -> Style["a.产量,a.Yield", Black, 20, Bold],
Axes -> True, AxesStyle -> Directive[Black, Thick],
TicksStyle -> Directive[Black, 16],
Ticks -> {Range[300, 600, 100], Range[0, 800, 200],
Range[0, 20000, 5000]},
BoxStyle -> Dashed, ImageSize -> 600];
plot3 = Plot3D[f[x, y], {x, y} \[Element] \[ScriptCapitalR],
Mesh -> None, ColorFunction -> "Rainbow",
PlotStyle -> Opacity[0.8`], PlotLegends -> Automatic];
Show[plot1, plot3]
2020年02月05日 05点02分 4
哇塞[大拇指] 此时,该彩色区域对应的x和y的范围该怎么求解呢?
2020年02月05日 06点02分
@我是第一名哈00 ImplicitRegion那句就是对应的范围,建议看代码时遇到不明白的地方按F1搜索一下
2020年02月05日 12点02分
@无影东瓜 好的 谢谢啦 您指导的 我正在吸收学习
2020年02月05日 16点02分
level 2
data2 = {{446, 651, 14850}, {382, 589, 15673}};
f[x_, y_] = -11917.525 + 72.999*x - 0.061*x^2 + 32.143*y -
0.028102*(x*y) - 0.015041*y^2;
plot2 = ListPointPlot3D[data2,
ColorFunction -> Function[{x, y, z}, Hue[0.03, 1, 1]]];
plot1 = Plot3D[f[x, y], {x, 300, 600}, {y, 0, 800},
MeshStyle -> Directive[GrayLevel[0], Dotted], Mesh -> Automatic,
MeshFunctions -> Automatic,
PlotStyle -> Directive[GrayLevel[0], Opacity[0.264`]],
PlotRange -> {0, 20000}, Axes -> True,
AxesStyle -> Directive[Black, Thick],
TicksStyle -> Directive[Black, 16],
Ticks -> {Range[300, 600, 100], Range[0, 800, 200],
Range[0, 20000, 5000]}, BoxStyle -> Dashed, ImageSize -> 600];
fmax = MaxValue[{f[x, y], 300 <= x <= 600 && 0 <= y <= 800}, {x, y}];
\[ScriptCapitalR] = ImplicitRegion[f[x, y] >= 0.95 fmax, {x, y}];
plot3 = Plot3D[f[x, y], {x, y} \[Element] \[ScriptCapitalR],
Mesh -> None, ColorFunction -> "Rainbow",
PlotStyle -> Opacity[0.8`], PlotLegends -> Automatic];
Show[plot1, plot2, plot3,
AxesLabel -> (MapThread[
Rotate[Text@
Style[#1, 16,
TextAlignment ->
Center], #2] &, {{"灌水量\nIrrigation amount(mm)",
"施肥量\nFertigation/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \
\(-2\)]\))",
"产量\nYield/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \
\(-2\)]\))"}, {-30 \[Degree], 60 \[Degree], 90 \[Degree]}}])]
运用上面这种方法时,三个小图可以有机的组合在一起,但是用下面的代码和三个小图组合时,始终得不到想要的结果,是我顺序放错了吗或者是还有其他的原\
因,具体该怎么组合,请大神赐教,我是新手,麻烦您啦!
Show[plot1, plot2, plot3,
labels = {"灌水量\nIrrigation amount(mm)",
"施肥量\nFertigation/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \
\(-2\)]\))",
"产量\nYield/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \
\(-2\)]\))"};
tmp = Manipulate[plist = p;
\[Alpha]list = {\[Alpha]1, \[Alpha]2, \[Alpha]3};
Graphics[{Inset[plot1, Center, Center, Scaled[.8]],
MapThread[
Rotate[Text[
Style[#1, 16, TextAlignment -> Center], #2], #3] &, {labels,
plist, \[Alpha]list}]}, ImageSize -> 600,
PlotRange -> {{-1, 1}, {-1, 1}, {-1,
1}}], {{p, {{-.8, -.8}, {.8, -.8}, {-.8, .8}}},
Locator}, {{\[Alpha]1, -30 \[Degree]}, -\[Pi], \[Pi]}, \
{{\[Alpha]2, 60 \[Degree]}, -\[Pi], \[Pi]}, {{\[Alpha]3,
90 \[Degree]}, -\[Pi], \[Pi]}]
2020年02月05日 17点02分 6
吧务
level 12
因为Manipulate不能放进Show里面,它的作用只是调整plist和alphalist参数
先单独运行Manipulate那句,调整好参数后 另起一个单元 运行Show的代码
或者如果你还是弄不清Manipulate的话,直接运行下面的代码
data2 = {{446, 651, 14850}, {382, 589, 15673}};
f[x_, y_] = -11917.525 + 72.999*x - 0.061*x^2 + 32.143*y -
0.028102*(x*y) - 0.015041*y^2;
plot2 = ListPointPlot3D[data2,
ColorFunction -> Function[{x, y, z}, Hue[0.03, 1, 1]]];
plot1 = Plot3D[f[x, y], {x, 300, 600}, {y, 0, 800},
MeshStyle -> Directive[GrayLevel[0], Dotted], Mesh -> Automatic,
MeshFunctions -> Automatic,
PlotStyle -> Directive[GrayLevel[0], Opacity[0.264`]],
PlotRange -> {0, 20000}, Axes -> True,
AxesStyle -> Directive[Black, Thick],
TicksStyle -> Directive[Black, 16],
Ticks -> {Range[300, 600, 100], Range[0, 800, 200],
Range[0, 20000, 5000]}, BoxStyle -> Dashed, ImageSize -> 600];
fmax = MaxValue[{f[x, y], 300 <= x <= 600 && 0 <= y <= 800}, {x, y}];
\[ScriptCapitalR] = ImplicitRegion[f[x, y] >= 0.95 fmax, {x, y}];
plot3 = Plot3D[f[x, y], {x, y} \[Element] \[ScriptCapitalR],
Mesh -> None, ColorFunction -> "Rainbow",
PlotStyle -> Opacity[0.8`]];
labels = {"灌水量\nIrrigation amount(mm)",
"施肥量\nFertigation/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \
\(-2\)]\))",
"产量\nYield/(kg\[CenterDot]\!\(\*SuperscriptBox[\(hm\), \(-2\)]\))"};
plist = {{-0.232, -0.538`}, {0.698`, -0.372`}, {-0.905`, -0.008}};
\[Alpha]list = {-0.45238934211693027`, 60 \[Degree], 90 \[Degree]};
Legended[Graphics[{Inset[Show[plot1, plot2, plot3], Center, Center,
Scaled[.8]],
MapThread[
Rotate[Text[
Style[#1, 16, TextAlignment -> Center], #2], #3] &, {labels,
plist, \[Alpha]list}]
}, ImageSize -> 600, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}],
BarLegend[{"Rainbow", {0.95 fmax, fmax}}]]
2020年02月06日 03点02分 7
谢谢指导,学到了很多,麻烦您啦,再次感谢[玫瑰]
2020年02月06日 04点02分
1