ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 19 Jul 2020 16:06:48 +0200Spline interpolation varies hugely when variables are rescaled in 3d-lists ?https://ask.sagemath.org/question/52429/spline-interpolation-varies-hugely-when-variables-are-rescaled-in-3d-lists/Dear all,
Here is a short script:
----------
(nbx, nby) = (74, 90)
def fx(x):
return (0.5 + x/2.5)
def fy(y):
return (40*y)
zetaPlot = list_plot3d([(30 * (fx(x/nbx)-1/2)+1/2 , fy(y/nby), 5 * abs(zeta(fx(x/nbx) + I*fy(y/nby))))
for x in range(-nbx, nbx+1) for y in range(-nby, nby+1)],
interpolation_type = 'spline')
zetaPlot.show()
----------
Now modify the z-coordinate: replace "5 * abs(zeta...)" by "abs(zeta...)"
The resulting graph is essentially flat. Can anyone tell me what is happening there?
Also, I would like to get rid of my scaling parameters 30 and 5 by using frame_aspect_ratio, to get cleaner code and a better annoted frame, but I don't seem to understand how to do it.
A great many thanks for anyone who would take the time to teach me that, it is some hours that I'm struggling with some docs and examples without having reached much --
Best, OlivierSat, 11 Jul 2020 15:05:32 +0200https://ask.sagemath.org/question/52429/spline-interpolation-varies-hugely-when-variables-are-rescaled-in-3d-lists/Answer by slelievre for <p>Dear all, </p>
<p>Here is a short script:</p>
<hr>
<pre><code>(nbx, nby) = (74, 90)
def fx(x):
return (0.5 + x/2.5)
def fy(y):
return (40*y)
zetaPlot = list_plot3d([(30 * (fx(x/nbx)-1/2)+1/2 , fy(y/nby), 5 * abs(zeta(fx(x/nbx) + I*fy(y/nby))))
for x in range(-nbx, nbx+1) for y in range(-nby, nby+1)],
interpolation_type = 'spline')
zetaPlot.show()
</code></pre>
<hr>
<p>Now modify the z-coordinate: replace "5 * abs(zeta...)" by "abs(zeta...)"
The resulting graph is essentially flat. Can anyone tell me what is happening there?
Also, I would like to get rid of my scaling parameters 30 and 5 by using frame_aspect_ratio, to get cleaner code and a better annoted frame, but I don't seem to understand how to do it.</p>
<p>A great many thanks for anyone who would take the time to teach me that, it is some hours that I'm struggling with some docs and examples without having reached much --</p>
<p>Best, Olivier</p>
https://ask.sagemath.org/question/52429/spline-interpolation-varies-hugely-when-variables-are-rescaled-in-3d-lists/?answer=52472#post-id-52472The questions seems to split into two questions.
- Why do we get such different graphs when using `list_plot3d`
with spline interpolation, starting from two 3D point sets
whose only difference is a scaling of the z-values?
- How can we change the (x, y, z) aspect ratios when
viewing a plot?
## Why are the graphs so different?
I don't have an answer here...
Here is slightly rewritten code to reproduce the problem.
nx, ny = 74, 90
def fx(x):
return 0.5 + x/2.5
def fy(y):
return 40*y
def g(x, y):
xx = 30 * (fx(x/nx) - 1/2) + 1/2
yy = fy(y/ny)
zz = 5 * abs(zeta(fx(x/nx) + I*fy(y/ny)))
return xx, yy, zz
gxyz = [g(x, y)
for x in range(-nx, nx+1)
for y in range(-ny, ny+1)]
g_plot = list_plot3d(gxyz, interpolation_type='spline')
g_plot.show()
hxyz = [(x, y, z/5) for x, y, z in gxyz]
h_plot = list_plot3d(hxyz, interpolation_type='spline')
h_plot.show(aspect_ratio=(1, 1, 10))
One would expect the graphs to be scaled versions of each other,
but that's far from being the case!
This is possibly revealing a bug.
## How to apply different x, y, z scalings to a 3D plot?
Use `aspect_ratio` as above, adapting to the need.
For instance, to get the bounding box for `g_plot` closer to a cube:
g_plot.show(aspect_ratio=(3, 1, 4))
Wed, 15 Jul 2020 00:07:50 +0200https://ask.sagemath.org/question/52429/spline-interpolation-varies-hugely-when-variables-are-rescaled-in-3d-lists/?answer=52472#post-id-52472Comment by Olivier R. for <p>The questions seems to split into two questions.</p>
<ul>
<li><p>Why do we get such different graphs when using <code>list_plot3d</code>
with spline interpolation, starting from two 3D point sets
whose only difference is a scaling of the z-values?</p></li>
<li><p>How can we change the (x, y, z) aspect ratios when
viewing a plot?</p></li>
</ul>
<h2>Why are the graphs so different?</h2>
<p>I don't have an answer here...</p>
<p>Here is slightly rewritten code to reproduce the problem.</p>
<pre><code>nx, ny = 74, 90
def fx(x):
return 0.5 + x/2.5
def fy(y):
return 40*y
def g(x, y):
xx = 30 * (fx(x/nx) - 1/2) + 1/2
yy = fy(y/ny)
zz = 5 * abs(zeta(fx(x/nx) + I*fy(y/ny)))
return xx, yy, zz
gxyz = [g(x, y)
for x in range(-nx, nx+1)
for y in range(-ny, ny+1)]
g_plot = list_plot3d(gxyz, interpolation_type='spline')
g_plot.show()
hxyz = [(x, y, z/5) for x, y, z in gxyz]
h_plot = list_plot3d(hxyz, interpolation_type='spline')
h_plot.show(aspect_ratio=(1, 1, 10))
</code></pre>
<p>One would expect the graphs to be scaled versions of each other,
but that's far from being the case!</p>
<p>This is possibly revealing a bug.</p>
<h2>How to apply different x, y, z scalings to a 3D plot?</h2>
<p>Use <code>aspect_ratio</code> as above, adapting to the need.</p>
<p>For instance, to get the bounding box for <code>g_plot</code> closer to a cube:</p>
<pre><code>g_plot.show(aspect_ratio=(3, 1, 4))
</code></pre>
https://ask.sagemath.org/question/52429/spline-interpolation-varies-hugely-when-variables-are-rescaled-in-3d-lists/?comment=52562#post-id-52562Ok, now I understand that aspect_ratio modifies only the rendering and has no effect on the datas produced.
I also tried adding
C = ComplexField(200)
and replacing
zeta(fx(x/nx) + I*fy(y/ny))
by
C(zeta(fx(x/nx) + I*fy(y/ny)))
with the same output.Sun, 19 Jul 2020 16:06:48 +0200https://ask.sagemath.org/question/52429/spline-interpolation-varies-hugely-when-variables-are-rescaled-in-3d-lists/?comment=52562#post-id-52562