LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript Nugget #17: Customizing Plots

In MathScript Nugget #16, we saw several different types of 2D plots. These are a good start for looking at your data, but often you will want to customize the way they look when you are preparing a report or trying to dig deeper into your data.

To understand how to customize a plot, first we need to discuss about plot attributes. Every part of a plot has a list of attributes. Lines have attributes like width, color, and marker style. The plot area has attributes like title, axis labels, and grid style. And the plot window itself has attributes like position and size. The LabVIEW documentation lists attributes and their possible values for plot lines, plot areas, plot windows, and text. There are a few different ways to change the attributes of a part of a plot.

The first way to set attributes is by specifying their values when you create a plot. Almost all of the plot functions accept attributes as parameters. They do this either as (name,value) pairs or as specially formatted strings for some of the more common attributes. For example, you can set a simple plot to be marked with green circles and dotted lines like this:

 

 

plot(x, y, 'Color', [0 1 0], 'Marker', 'o', 'LineStyle', ':') % (name,value) pairs

 

or like this

 

 

plot(x, y, 'go:') % attribute string

 

 

 

 

 

plotFormat.png

 

The (name,value) pairs offer more options, but the string syntax is more succinct and quicker to type.

The second way to set attributes is to use functions that operate on plot objects. Plot objects are a variables of a special datatype that are returned by many of the plot functions. For example, 'plot' returns a reference to its line and 'axes' returns references to the most recently created axes. You can then pass these references to the 'set' function, along with (name,value) pairs, to set attributes of that plot object.

The advantage of plot objects over specifying attributes when you create the plot is that you can write one function or script that can customize many different plots. For example, if you always like your plots to have a certain appearance, you could write a .m file that accepts any plot object and modifies its style to your liking. Then you could call this function on every plot that you create, instead of trying to remember all the relevant attributes every time you create a plot.

The final way to customize a plot is less programmatic and more interactive. Once you have created a plot object for a particular plot, you can use a nice user interface from the MathScript Window to modify attributes of that plot. You access this interface by clicking on the plot object's name in the Variables tree. Then you can edit various attributes, press the 'Update' button, and see how your new plot looks. Note that you can currently only edit colors and enum type options. String attributes like FontName and numeric attributes like LineWidth are not currently supported from this interface.

plotObject.png

jattas
LabVIEW MathScript R&D

ps Check out more MathScript Nuggets!

0 Kudos
Message 1 of 1
(6,148 Views)