:

## colorbar for a 3D plot in Maple 2015.1

Maple 2015
This post in reply to the Question, colormap in plot3d

The question of colorbars for plots comes up now and then.

One particular theme involves creating an associated 2D plot as the colorbar, using the data within the given 3D plot. But the issue arises of how to easily display the pair together. I'll mention that Maple 2015.1 (the point-release update) provides quite a simple way to accomplish the display of a 3D plot and an associated 2D colorbar side-by-side.

I'm just going to use the example of the latest Question on this topic. There are two parts to here. The first part involves creating a suitable colorbar as a 2D plot, based on the data in the given 3D plot. The second part involves displaying both together.

Here's the 3D plot used for motivating example, for which in this initial experiment I'll apply shading by using the z-value for hue shading. There are a few ways to do that, and a more complete treatment of the first part below would be to detect the shading scheme and compute the colorbar appropriately.

Some of the code below requires update release Maple 2015.1 in order to work. The colors look much better in the actual Maple Standard GUI than they do in this mapleprimes post (rendered by MapleNet).

```f := 1.7+1.3*r^2-7.9*r^4+16*r^6:

P := plot3d([r, theta, f],
r=0..1, theta=0..2*Pi, coords=cylindrical,
color=[f,1,1,colortype=HSV]):

P;``` Now for the first part. I'll construct two variants, one for a vertical colorbar and one for a horizontal colorbar.

I'll use the minimal and maximal z-values in the data of 3D plot P. This is one of several aspects that needs to be handled according to what's actually inside the 3D plot's data structure.

```zmin,zmax := [min,max](op([1,1],P)[..,..,3])[]:

verthuebar := plots:-densityplot(z, dummy=0..1, z=zmin..zmax, grid=[2,49],
size=[90,260], colorstyle=HUE,
style=surface, axes=frame, labels=[``,``],
axis=[tickmarks=[]]):

horizhuebar := plots:-densityplot(z, z=zmin..zmax, dummy=0..1, grid=[49,2],
size=[300,90], colorstyle=HUE,
style=surface, axes=frame, labels=[``,``],
axis=[tickmarks=[]]):
```

Now we can approach the second part, to display the 3D plot and its colorbar together.

An idea which is quite old is to use a GUI Table for this. Before Maple 2015 that could be done by calling plots:-display on an Array containing the plots. But that involves manual interation to fix it up to look nice: the Table occupies the full width of the worksheet's window and must be resized with the mouse cursor, the relative widths of the columns are not right and must be manually adjusted, the Table borders are all visible and (if unwanted) must be hidden using context-menu changes on the Table, etc. And also the rendering of 2D plots in the display of the generated _PLOTARRAY doesn't respect the size option if applied when creating 2D plots.

I initially thought that I'd have to use several of the commands for programmatic content generation (new in Maple 2015) to build the GUI Table. But in the point-release Maple 2015.1 the size option on 2D plots is respected when using the DocumentTools:-Tabulate command (also new to Maple 2015). So the insertion and display is now possible with that single command.

```DocumentTools:-Tabulate([P,verthuebar],
exterior=none, interior=none,
weights=[100,25], widthmode=pixels, width=420);```  ```DocumentTools:-Tabulate([[P],[horizhuebar]],
exterior=none, interior=none);
```  We may also with to restrict the view, vertically, and have the colorbar match the shades that are displayed.

```DocumentTools:-Tabulate([plots:-display(P,view=2..5),
plots:-display(verthuebar,view=2..5)],
exterior=none, interior=none,
weights=[100,25], widthmode=pixels, width=420);
```  ```DocumentTools:-Tabulate([[plots:-display(P,view=2..5)],
[plots:-display(horizhuebar,view=[2..5,default])]],
exterior=none, interior=none);
```  I'd like to wrap both parts into either one or two procedures, and hopefully I'd find time to do that and post here as a followup comment.

Apart from considerations such as handling various kinds of 3D plot data (GRID vs MESH, etc, in the data structure) there are also the matters of detecting a view (VIEW) if specified when creating the 3D plot, handling custom shading schemes, and so on. And then there's the matter of what to do when multiple 3D surfaces (plots) have been merged together.

It's also possible that the construction of the 2D plot colorbar is the only part which requires decent programming as a procedure with special options. The Tabulate command already offers options to specify the placement, column weighting, Table borders, etc. Perhaps it's not necessary to roll both parts into a single command.

3dhuecolorbarA.mw

acer ﻿