Showing an organised top down view of a 3D function in Maxima

Viewed 187

I asked on the math site and was told to ask this here.

I'm trying to use Maxima to show the top down view of a 3D function, the different values (height/depth) of the function will be shown using a range of colours and a colour bar that Maxima provides automatically.

Using this website I was able to put together some code for the top down view of the function (the code before I decided to leave out, as it was just load(draw)$ and the function itself):

wxdraw3d(
enhanced3d=true, explicit(f(y,x,15,400,1),y,0,100,x,20,30),
xu_grid=100, yv_grid=100,
xyplane=0,
view=[0,0],
zrange=[0,50],
zlabel="Gap distance (m)",
xlabel="Gap number",
ylabel="Initial velocity (ms^{-1})",
title="f(n,u,15,400,1)"
);

Which gives the following plot:

Which gives the following plot

As you can see, there's several issues with the plot:

  • The colour bar has no label, which would use the current z-label
  • The vertical axis (label, numbers and the subdivisions) should be on the left hand side
  • The subdivisions of the horizontal axis should be on the bottom
  • All subdivisions on the plot should appear above and not underneath
  • Border should be resized so nothing is cut off or overlapping (referring to the black border around the output, the image was a crop of inside the border)

I tried another method from this website using the gnuplot code at the very bottom to give this modified code:

plot3d(
f(x,y,15,400,1),[x,0,100],[y,20,30],
[elevation,0],
[grid,100,100],
[zlabel,"Gap length (m)"],
[xlabel,"Gap number"],
[ylabel,"Initial velocity (ms^{-1})"],
[gnuplot_preamble,"set view map; unset surface"],
[gnuplot_pm3d,true]
);

However, that didn't work as it gave this plot. Which as you can see has way more problems than the first plot. Not only is it not as clear as the first plot, it barely resembles the plot from the website, there's less info, no colour bar, no numbered axes, an annoying grid, and even the colour gradient is worse.

For the first code I used, I could not find anything about labelling the colour bar, only the range, the colour itself and whether it is on or off; and I couldn't find anything on the border size or positioning of axis labels, etc. So there's no point trying to use this code yet, especially if I get the first code to work properly. With the size of the plot, I tried wxplot_size[], but that gave the error "draw: unknown option [600,400] ", it seems to round up to the nearest hundred.

Is there any way to modify the first code such that the colour bar is labelled, the vertical axis labelling is on the other side, the small subdivisions of each axis appear over the plot, and nothing outside of the plot is cut off or overlapping? If it's not possible to move the subdivisions to be above the plot, is there anyway to remove them? I don't know much about Maxima or gnuplot .

Everything else seems fine apart from those issues, and I'm not entirely sure where else to ask about Maxima.

1 Answers

Let's modify the wxdraw3d command.

Maxima writes a gnuplot input file which is loaded by gnuplot afterwards, so you can check the influence of maxima commands. On my system (Debian linux) the file is in my home directory and has a name like "~/maxout_28503.gnuplot".

Most of the issues can be solved with using the gnuplot command set view map instead of set view 0,0, corresponding to maxima command view=map instead of view=[0,0].

I have not found a "nice" way for setting the label of the colorbox. I think there is a maxima way, because by default the generated gnuplot file contains the line set cblabel '' which generates an empty label. But we can use the mechanism for applying any gnuplot setting: user_preamble= ....

So now we have the following:

wxdraw3d(
    user_preamble="set cblabel 'Gap distance (m)' offset screen 0.01, 0;",
    view=map,
    enhanced3d=true,
    title="f(n,u,15,400,1)",
    xlabel="Gap number",
    ylabel="Initial velocity (ms^{-1})",
    zlabel="",
    explicit(x^2+y^2,x,-2,2,y,-2,2)
);

The commands written in user_preamble= seem to be executed just before the actual gnuplot splot command. They therefore can overwrite previous settings.

The command set cblabel sets the label of the colorbox. I have added a small offset to avoid that the label is too close.

I'm too lazy to understand your function :) so I plot another one.

This is the result:

result


Update to improve the picture from your comment

result

Gnuplot sometimes has problems with estimating text sizes. This can lead to ugly diagrams. You can improve the output by manually adjusting offsets and sizes.

The command set size changes the area of the plot within the complete image. This can be used to make some space for the colorbox label on the right side. The set ylabel command accepts an offset. We put both commands into the user_preamble section wxdraw3d:

wxdraw3d(
    user_preamble=[
        "set cblabel 'Gap distance (m)' offset screen 0.01, 0",
        "set ylabel offset screen -0.01,0",
        "set size 0.9,1"
    ],
    view=map,
    enhanced3d=true,
    ...
);

Play with all of the offset and size numbers until they fit.

Related