Visualization

Background Images on Plots

ColorTools Updates

Custom Plot Shading

Fractals

Signal Processing

Time Series

HyperlinkImage 

HyperlinkImage 

HyperlinkImage 

HyperlinkImage 

HyperlinkImage 

HyperlinkImage 

 

Background Images on Plots

Plots have several new options that make it possible to add a background image, as well as to programmatically set the plot size. 

> with(plots); -1with(plottools); -1
 

Example 

Changing the size or background color of a plot is easily done using new options for plotting commands. 

> plot(cos(x), x = `+`(`-`(`*`(2, `*`(Pi)))) .. `+`(`*`(2, `*`(Pi))), color = red, axis = [color = white], size = [.5, 300], background =
plot(cos(x), x = `+`(`-`(`*`(2, `*`(Pi)))) .. `+`(`*`(2, `*`(Pi))), color = red, axis = [color = white], size = [.5, 300], background =
plot(cos(x), x = `+`(`-`(`*`(2, `*`(Pi)))) .. `+`(`*`(2, `*`(Pi))), color = red, axis = [color = white], size = [.5, 300], background =
plot(cos(x), x = `+`(`-`(`*`(2, `*`(Pi)))) .. `+`(`*`(2, `*`(Pi))), color = red, axis = [color = white], size = [.5, 300], background =
plot(cos(x), x = `+`(`-`(`*`(2, `*`(Pi)))) .. `+`(`*`(2, `*`(Pi))), color = red, axis = [color = white], size = [.5, 300], background =
 

Plot_2d 

 

Example 

Background images can be used to show the connection between mathematical expressions and real life structures. In this example, a parabola follows the rails of a roller coaster. 

> imagefile := FileTools:-JoinPath([kernelopts(datadir),
display(plot(`+`(3.5, `-`(`*`(`^`(`+`(x, `-`(`/`(1, 2))), 2)))), thickness = 5, color = red), view = [-3 .. 3, 0 .. 4], axis = [color = blue], background = imagefile)
display(plot(`+`(3.5, `-`(`*`(`^`(`+`(x, `-`(`/`(1, 2))), 2)))), thickness = 5, color = red), view = [-3 .. 3, 0 .. 4], axis = [color = blue], background = imagefile)
display(plot(`+`(3.5, `-`(`*`(`^`(`+`(x, `-`(`/`(1, 2))), 2)))), thickness = 5, color = red), view = [-3 .. 3, 0 .. 4], axis = [color = blue], background = imagefile)
display(plot(`+`(3.5, `-`(`*`(`^`(`+`(x, `-`(`/`(1, 2))), 2)))), thickness = 5, color = red), view = [-3 .. 3, 0 .. 4], axis = [color = blue], background = imagefile)
display(plot(`+`(3.5, `-`(`*`(`^`(`+`(x, `-`(`/`(1, 2))), 2)))), thickness = 5, color = red), view = [-3 .. 3, 0 .. 4], axis = [color = blue], background = imagefile)
 

Plot_2d 

 

Example 

The following example plots the location of all earthquakes of magnitude 2.5 or greater over a 7 day period. Data compiled by the U.S. Geological Survey.  

Plot_2d 

For more details on these new options, see the Background Images page.


ColorTools and Color Palettes in Maple 18

Several new commands in the ColorTools package allow collections of colors (palettes) to be extended or reduced. Such collections of colors can be easily used in the shading of multiple plot objects. 

This section illustrates the functionality by extracting the colors from an external image file, reducing the full collection of its colors to a small representative list, extending that collection with additional colors, sorting that larger collection to increase visual distinction, and then using the final collection of colors as the basis of a new plotting color palette. 

In addition, we demonstrate a new way to visualize collections of colors. 

> restart; -1with(ImageTools); -1with(ColorTools); -1with(plots); -1
 

We can begin by reading an image file into the Maple session. The resulting Array structure is interpreted by Maple as an image, and can be viewed or embedded directly in the current document. The ability to programmatically embed images directly into your document is new in Maple 18. 

> imgfile := FileTools:-JoinPath([kernelopts(datadir),
> Embed(Scale(ImageTools:-Read(imgfile), .5))
 

Image 

 

The colors can be extracted from the image. The ColorsFromImage command can extract from the image a list of Color objects as a format understood by the ColorTools package. 

> full := ColorsFromImage(imgfile); -1numelems(full)
 
805
 

Below is a small selection of those colors. 

> full[610 .. 630]
 

 

The new SpatterPlot and SpatterPlot3d commands of Maple 18 allow us to visualize the distribution of colors in the image in either two or three dimensions. These new commands also allow the colors to be plotted in various color spaces. 

Here are the colors from the image, plotted in terms of the RGB and Lab color spaces. 

> display(Array([SpatterPlot3d(full, space =
 

Plot_2d Plot_2d

 

Using the ReducePalette command, the list of colors from the image can be reduced to a much smaller, but still representative, list of colors. 

> reduced := ReducePalette(full)
 
 
> numelems(reduced)
 
4
 

The small list of representative colors can be further expanded to produce a larger palette. 

> new := ExpandPalette(reduced, number = 16)
 

 

The above list of colors is not ordered in a manner suitable for plotting multiple curves, since the colors near the start of the list are too close together. Notice that the first and fourth colors are not readily distinguishable. 

The expanded list of colors can be sorted by the new SortPalette command, so that the earlier colors are farther apart. This can make the final list of colors more suitable as a palette for plotting multiple curves, since the earlier colors will be more visually distinguishable in the given color space. 

> final := SortPalette(new)
 

 
> display(seq(plot(`*`(x, `*`(i)), x = 5 .. 10, thickness = 4, color = final[i]), i = 1 .. 5))
 
Plot_2d
 

To set a new color palette for plotting, pass the above final color list to the setcolors command. This allows the colors to be used for shading multiple curves without requiring any reference to the color list within the plotting commands. 

The Color object is just one of several formats to denote color that the setcolors command supports.  

> setcolors(ColorTools:-Palette(final)); -1
 

> plot([seq(`*`(x, `*`(i)), i = 1 .. 5)], x = 5 .. 10, thickness = 4)
 

Plot_2d
 

> Student:-Calculus1:-ApproximateInt(sin(x), 0 .. Pi, output = plot)
Student:-Calculus1:-ApproximateInt(sin(x), 0 .. Pi, output = plot)
 

Plot_2d
 

> Student:-MultivariateCalculus:-ApproximateInt(`*`(sin(x), `*`(sin(y))), x = -3 .. 3, y = -3 .. 3, z = -2 .. 2, output = plot, partition = [5, 5])
Student:-MultivariateCalculus:-ApproximateInt(`*`(sin(x), `*`(sin(y))), x = -3 .. 3, y = -3 .. 3, z = -2 .. 2, output = plot, partition = [5, 5])
Student:-MultivariateCalculus:-ApproximateInt(`*`(sin(x), `*`(sin(y))), x = -3 .. 3, y = -3 .. 3, z = -2 .. 2, output = plot, partition = [5, 5])
Student:-MultivariateCalculus:-ApproximateInt(`*`(sin(x), `*`(sin(y))), x = -3 .. 3, y = -3 .. 3, z = -2 .. 2, output = plot, partition = [5, 5])
 

Plot_2d
 

 

The extended palette can be plotted together with the original full list of colors from the image. 

> SpatterPlot([full[], final[]])
 
Plot_2d
 

 

Custom Plot Shading

Custom shading schemes are now supported for three-dimensional plotting when using the plot3d command as well as for two-dimensional density-style plotting using the surfdata command. Shading can be specified using coloring procedures, color data from existing 3-D plots, or images. 

Examples 

Continuing the example from the ColorTools section above, we can see how 3-D plots can now be easily shaded with color gradients. In this example, this is done using the RGB color space equivalent colors from the reduced list. 

> reducedrgb := map2(Color,
 
 
> plot3d(1, t = `+`(`-`(Pi)) .. Pi, p = 0 .. Pi, colorscheme = [
 
Plot_2d
 

A 3-D plot can also be shaded with an image, a form of texture mapping. In the following example we apply a satellite map (image courtesy of NASA Blue Marble Next Generation) to a sphere to generating a representation to the Earth as a globe. 

> plot3d(-1, t = `+`(`-`(Pi)) .. Pi, p = 0 .. Pi, image =
plot3d(-1, t = `+`(`-`(Pi)) .. Pi, p = 0 .. Pi, image =
 

Image 

 

For more details, see Custom Plot Shading.



Extruding 2-D Plots to 3-D

Another feature added in Maple 18 with applicability to 3-D plotting and solid modeling is the extrude command. 

This takes a 2-D plot and extrudes it along a specified path. The default path is a uniform extrusion in the z-direction over the specified interval. 

f := plot({`+`(1, `-`(sin)), `+`(sin, 1)}, `+`(`-`(`*`(2, `*`(Pi)))) .. `+`(`*`(2, `*`(Pi)))); -1 

plots[display](f) 

Plot_2d
 

 

 

poly := [[0, 1], [0, 2], [.5, 2.75], [1.25, 3], [2, 2.75], [2.5, 2.25], [1.75, 1.5], [2.5, .75], [2, .25], [1.25, 0], [.5, .25]]; -1
poly := [[0, 1], [0, 2], [.5, 2.75], [1.25, 3], [2, 2.75], [2.5, 2.25], [1.75, 1.5], [2.5, .75], [2, .25], [1.25, 0], [.5, .25]]; -1
 

g := plots[polygonplot](poly, axes = none, color =  

Plot_2d
 

plottools[extrude](f, 0 .. 1) 

Plot_2d
 

extrusionMap := proc (x, y, t) options operator, arrow; [`+`(x, `*`(`/`(1, 4), `*`(cos(`+`(x, t))))), `+`(y, `*`(`/`(1, 4), `*`(sin(`+`(x, t))))), t] end proc; -1 

plottools[extrude](g, 0 .. 5, extrusionMap, numsegments = 10) 

Plot_2d
 


Fractals

The new Fractals package makes it easier to create and explore popular fractals, including Mandelbrot, Julia, Newton, and other time-iterative fractals. 

> with(Fractals:-EscapeTime); -1
 
> with(ImageTools); -1
 
> M := Mandelbrot(500, `+`(`-`(2.0), `-`(`*`(1.35, I))), `+`(.7, `*`(1.35, I))); -1
 
> Embed(M); 1
 

Image 

For more information on the new Fractals package, see Escape-Time Fractals.


Signal Processing Visualizations

The Signal Processing package now features new commands for generating spectrograms as well as plots for signals. 

To find out about other new functionality for Signal Processing, see Updates in Signal Processing

Example 

> with(SignalProcessing); -1
 
> data := Vector(`^`(2, 8), proc (i) options operator, arrow; `+`(sin(`+`(`*`(`/`(1, 5), `*`(evalf(Pi), `*`(i))))), `*`(`/`(1, 1000000000000), `*`(rand()))) end proc, datatype = float[8]); -1
 
> Spectrogram(BlackmanNuttallWindow(data), samplerate = 50, includepowerspectrum, includesignal, fftsize = 128, colorscheme = [
Spectrogram(BlackmanNuttallWindow(data), samplerate = 50, includepowerspectrum, includesignal, fftsize = 128, colorscheme = [
Spectrogram(BlackmanNuttallWindow(data), samplerate = 50, includepowerspectrum, includesignal, fftsize = 128, colorscheme = [
Spectrogram(BlackmanNuttallWindow(data), samplerate = 50, includepowerspectrum, includesignal, fftsize = 128, colorscheme = [
Spectrogram(BlackmanNuttallWindow(data), samplerate = 50, includepowerspectrum, includesignal, fftsize = 128, colorscheme = [
Spectrogram(BlackmanNuttallWindow(data), samplerate = 50, includepowerspectrum, includesignal, fftsize = 128, colorscheme = [
 

Plot_2d
Plot_2d
Plot_2d

  

 

Time Series Analysis Visualizations

The new Time Series Analysis package features several new plots, including TimeSeriesPlot, which displays time series data, and SeasonalSubseriesPlot, which displays seasonal time series data. 

For more details on this package, see New Time Series Analysis Package

Example 

> with(TimeSeriesAnalysis); -1
 
> TS1 := TimeSeries([7, 23, 21, 19, 13, 46, 42, 30, 31, 26, 19, 9, 16, 26, 17, 33, 31, 46, 42, 35, 45, 30, 11, 17, 23, 20, 15, 36, 31, 55, 49, 39, 36, 28, 12, 11, 21, 23, 27, 33, 36, 49, 42, 37, 33, 45,...
TS1 := TimeSeries([7, 23, 21, 19, 13, 46, 42, 30, 31, 26, 19, 9, 16, 26, 17, 33, 31, 46, 42, 35, 45, 30, 11, 17, 23, 20, 15, 36, 31, 55, 49, 39, 36, 28, 12, 11, 21, 23, 27, 33, 36, 49, 42, 37, 33, 45,...
TS1 := TimeSeries([7, 23, 21, 19, 13, 46, 42, 30, 31, 26, 19, 9, 16, 26, 17, 33, 31, 46, 42, 35, 45, 30, 11, 17, 23, 20, 15, 36, 31, 55, 49, 39, 36, 28, 12, 11, 21, 23, 27, 33, 36, 49, 42, 37, 33, 45,...
 
TS1 := Vector[column](%id = 18446744078190094926)
 

To display a simple plot of the Time Series, use the TimeSeriesPlot command. 

> TimeSeriesPlot(TS1)
 

Plot_2d

 

To show seasonal Time Series data, use the SeasonalSubseriesPlot command. 

> SeasonalSubseriesPlot(TS1)
 
Plot_2d