Fplot Legend
- Fplot Legend
- Plot Legend In R
- Plot Legend Python
- Plot Legend Mathematica
- Plot Legend Outside Of Plot Matplotlib
Fplot uses adaptive step control to produce a representative graph, concentrating its evaluation in regions where the function's rate of change is the greatest. Examples Plot the hyperbolic tangent function from -2 to 2. Analytics cookies. We use analytics cookies to understand how you use our websites so we can make them better, e.g. They're used to gather information about the pages you visit and how many clicks you need to accomplish a task. A short Matlab tutorial (part 4 of 4). In this part, I define a function using a function handle and then plot it using the fplot function. Prepared by Wil.
Gaussian Process Regression Models
Gaussian process regression (GPR) models are nonparametric kernel-basedprobabilistic models. You can train a GPR model using the fitrgp
function.
Consider the training set ,where and ,drawn from an unknown distribution. A GPR model addresses the questionof predicting the value of a response variable ,given the new input vector ,and the training data. A linear regression model is of the form
where .The error variance σ2 andthe coefficients β are estimated from thedata. A GPR model explains the response by introducing latent variables, ,from a Gaussian process (GP), and explicit basis functions, h.The covariance function of the latent variables captures the smoothnessof the response and basis functions project the inputs intoa p-dimensional feature space.
A GP is a set of random variables, such that any finite numberof them have a joint Gaussian distribution. If isa GP, then given n observations ,the joint distribution of the random variables isGaussian. A GP is defined by its mean function andcovariance function, .That is, if isa Gaussian process, then and
Now consider the following model.
where ,that is f(x) are from a zeromean GP with covariance function, . h(x)are a set of basis functions that transform the original feature vector x inRd into a new featurevector h(x) in Rp. β isa p-by-1 vector of basis function coefficients.This model represents a GPR model. An instance of response y canbe modeled as
Hence, a GPR model is a probabilistic model. There is a latentvariable f(xi)introduced for each observation ,which makes the GPR model nonparametric. In vector form, this modelis equivalent to
where
The joint distribution of latent variables inthe GPR model is as follows:
close to a linear regressionmodel, where looksas follows:
The covariance function is usually parameterized by a set of kernel parameters or hyperparameters, .Often iswritten as toexplicitly indicate the dependence on .
fitrgp
estimates the basisfunction coefficients, ,the noise variance, ,and the hyperparameters,,of the kernel function from the data while training the GPR model.You can specify the basis function, the kernel (covariance) function,and the initial values for the parameters.
Because a GPR model is probabilistic, it is possible to compute the prediction intervals using the trained model (see predict
and resubPredict
).
You can also compute the regression error using the trained GPR model (see loss
and resubLoss
).
Compare Prediction Intervals of GPR Models
This example fits GPR models to a noise-free data set and a noisy data set. The example compares the predicted responses and prediction intervals of the two fitted GPR models.
Generate two observation data sets from the function .
The values in y_observed1
are noise free, and the values in y_observed2
include some random noise.
Fit GPR models to the observed data sets.
Compute the predicted responses and 95% prediction intervals using the fitted models.
Resize a figure to display two plots in one figure.
Create a 1-by-2 tiled chart layout.
For each tile, draw a scatter plot of observed data points and a function plot of . Then add a plot of GP predicted responses and a patch of prediction intervals.
When the observations are noise free, the predicted responses of the GPR fit cross the observations. The standard deviation of the predicted response is almost zero. Therefore, the prediction intervals are very narrow. When observations include noise, the predicted responses do not cross the observations, and the prediction intervals become wide.
References
[1] Rasmussen, C. E. and C. K. I. Williams. GaussianProcesses for Machine Learning. MIT Press. Cambridge,Massachusetts, 2006.
See Also
fitrgp
predict
RegressionGP
Related Topics
Next: Multiple Plots on One Page, Previous: Three-Dimensional Plots, Up: High-Level Plotting [Contents][Index]
15.2.3 Plot Annotations
You can add titles, axis labels, legends, and arbitrary text to anexisting plot. For example:
The functions grid
and box
may also be used to add gridand border lines to the plot. By default, the grid is off and theborder lines are on.
Finally, arrows, text and rectangular or elliptic boxes can be added tohighlight parts of a plot using the annotation
function. Those objectsare drawn in an invisible axes, on top of every other axes.
Specify the string used as a title for the current axis.
An optional list of property/value pairs can be used to changethe appearance of the created title text object.
If the first argument hax is an axes handle, then plot into this axis,rather than the current axes returned by gca
.
The optional return value h is a graphics handle to the created textobject.
See also:xlabel, ylabel, zlabel, text.
Display a legend for the current axes using the specified strings as labels.
Legend entries may be specified as individual character string arguments,a character array, or a cell array of character strings.
If the first argument hax is an axes handle, then plot into this axis,rather than the current axes returned by gca
. If the handles,hobjs, are not specified then the legend’s strings will be associatedwith the axes’ descendants. legend
works on line graphs,bar graphs, etc. A plot must exist before legend is called.
The optional parameter pos specifies the location of the legendas follows:
pos | location of the legend |
---|---|
north | center top |
south | center bottom |
east | right center |
west | left center |
northeast | right top (default) |
northwest | left top |
southeast | right bottom |
southwest | left bottom |
outside | can be appended to any location string |
The optional parameter orient determines if the key elements areplaced vertically or horizontally. The allowed values are'vertical'
(default) or 'horizontal'
.
The following customizations are available using option:
'show'
Show legend on the plot
'hide'
Hide legend on the plot
'toggle'
Toggles between 'hide'
and 'show'
'boxon'
Show a box around legend (default)
'boxoff'
Hide the box around legend
'right'
Place label text to the right of the keys (default)
'left'
Place label text to the left of the keys
'off'
Delete the legend object
The optional output values are
The graphics handle of the legend object.
Graphics handles to the text and line objects which make up the legend.
Graphics handles to the plot objects which were used in making the legend.
A cell array of strings of the labels in the legend.
The legend label text is either provided in the call to legend
oris taken from the DisplayName property of graphics objects. If nolabels or DisplayNames are available, then the label text is simply'data1'
, 'data2'
, …, 'dataN'
.
Implementation Note: A legend is implemented as an additional axes objectof the current figure with the 'tag'
set to 'legend'
.Properties of the legend object may be manipulated directly by usingset
.
Create a text object with text string at position x, y,(z) on the current axes.
Multiple locations can be specified if x, y, (z) arevectors. Multiple strings can be specified with a character matrix ora cell array of strings.
Optional property/value pairs may be used to control the appearance of thetext.
The optional return value h is a vector of graphics handles to thecreated text objects.
See also:gtext, title, xlabel, ylabel, zlabel.
See Text Properties for the properties that you can set.
Specify the string used to label the x-axis of the current axis.
An optional list of property/value pairs can be used to changethe properties of the created text label.
If the first argument hax is an axes handle, then operate onthis axis rather than the current axes returned by gca
.
The optional return value h is a graphics handle to the created textobject.
See also:ylabel, zlabel, datetick, title, text.
Add labels to the contours of a contour plot.
The contour levels are specified by the contour matrix c which isreturned by contour
, contourc
, contourf
, andcontour3
. Contour labels are rotated to match the local lineorientation and centered on the line. The position of labels along thecontour line is chosen randomly.
If the argument h is a handle to a contour group object, then labelthis plot rather than the one in the current axes returned by gca
.
By default, all contours are labeled. However, the contours to label can bespecified by the vector v. If the 'manual'
argument isgiven then the contours to label can be selected with the mouse.
Additional property/value pairs that are valid properties of text objectscan be given and are passed to the underlying text objects. Moreover,the contour group property 'LabelSpacing'
is available whichdetermines the spacing between labels on a contour to be specified. Thedefault is 144 points, or 2 inches.
The optional return value h is a vector of graphics handles tothe text objects representing each label.The 'userdata'
property of the text objects contains the numericalvalue of the contour label.
An example of the use of clabel
is
See also:contour, contourf, contour3, meshc, surfc, text.
Control display of the axis border.
The argument may be either 'on'
or 'off'
. If it isomitted, the current box state is toggled.
If the first argument hax is an axes handle, then operate on thisaxis rather than the current axes returned by gca
.
See also:axis, grid.
Control the display of plot grid lines.
The function state input may be either 'on'
or 'off'
.If it is omitted, the current grid state is toggled.
When the first argument is 'minor'
all subsequent commandsmodify the minor grid rather than the major grid.
If the first argument hax is an axes handle, then operate onthis axis rather than the current axes returned by gca
.
To control the grid lines for an individual axis use the set
function. For example:
See also:axis, box.
Add a colorbar to the current axes.
A colorbar displays the current colormap along with numerical rulingsso that the color scale can be interpreted.
The optional input loc determines the location of the colorbar.Valid values for loc are
'EastOutside'
Place the colorbar outside the plot to the right. This is the default.
'East'
Place the colorbar inside the plot to the right.
'WestOutside'
Place the colorbar outside the plot to the left.
'West'
Place the colorbar inside the plot to the left.
'NorthOutside'
Place the colorbar above the plot.
'North'
Place the colorbar at the top of the plot.
'SouthOutside'
Place the colorbar under the plot.
'South'
Place the colorbar at the bottom of the plot.
To remove a colorbar from a plot use any one of the following keywords forthe delete_option: 'delete'
, 'hide'
, 'off'
.
If the argument 'peer'
is given, then the following argument istreated as the axes handle in which to add the colorbar. Alternatively,If the first argument hax is an axes handle, then the colorbar isadded to this axis, rather than the current axes returned by gca
.
If the first argument hcb is a handle to a colorbar object, thenoperate on this colorbar directly.
Additional property/value pairs are passed directly to the underlying axesobject.
The optional return value h is a graphics handle to the createdcolorbar object.
Implementation Note: A colorbar is created as an additional axes to thecurrent figure with the 'tag'
property set to 'colorbar'
.The created axes object has the extra property 'location'
whichcontrols the positioning of the colorbar.
See also:colormap.
Draw annotations to emphasize parts of a figure.
You may build a default annotation by specifying only the typeof the annotation.
Otherwise you can select the type of annotation and then set its positionusing either x and y coordinates for line-based annotations or aposition vector pos for others. In either case, coordinates areinterpreted using the 'units'
property of the annotation object.The default is 'normalized'
, which means the lower left hand cornerof the figure has coordinates ‘[0 0]’ and the upper right hand corner‘[1 1]’.
If the first argument hf is a figure handle, then plot into thisfigure, rather than the current figure returned by gcf
.
Further arguments can be provided in the form of prop/val pairsto customize the annotation appearance.
The optional return value h is a graphics handle to the createdannotation object. This can be used with the set
function tocustomize an existing annotation object.
All annotation objects share two properties:
'units'
: the units in which coordinates are interpreted.
Its value may be one of'centimeters'
'characters'
'inches'
'{normalized}'
'pixels'
'points'
.'position'
: a four-element vector [x0 y0 width height].
The vector specifies the coordinates (x0,y0) of the origin of the annotationobject, its width, and its height. The width and height may be negative,depending on the orientation of the object.
Valid annotation types and their specific properties are describedbelow:
'line'
Constructs a line. x and y must be two-element vectorsspecifying the x and y coordinates of the two ends of the line.
The line can be customized using 'linewidth'
, 'linestyle'
,and 'color'
properties the same way as for line
objects.
'arrow'
Fplot Legend
Construct an arrow. The second point in vectors x and yspecifies the arrowhead coordinates.
Besides line properties, the arrowhead can be customized using'headlength'
, 'headwidth'
, and 'headstyle'
properties. Supported values for 'headstyle'
property are:['diamond'
'ellipse'
'plain'
'rectangle'
'vback1'
'{vback2}'
'vback3'
]
'doublearrow'
Construct a double arrow. Vectors x and y specify thearrowhead coordinates.
The line and the arrowhead can be customized as for arrow annotations, butsome property names are duplicated:'head1length'
/'head2length'
,'head1width'
/'head2width'
, etc. The index 1 marks theproperties of the arrowhead at the first point in x and ycoordinates.
'textarrow'
Construct an arrow with a text label at the opposite end from the arrowhead.
Use the 'string' property to change the text string.The line and the arrowhead can be customized as for arrow annotations, andthe text can be customized using the same properties as text
graphicsobjects. Note, however, that some text property names are prefixed with'text' to distinguish them from arrow properties:'textbackgroundcolor'
, 'textcolor'
,'textedgecolor'
, 'textlinewidth'
,'textmargin'
, 'textrotation'
.
'textbox'
Construct a box with text inside. pos specifies the'position'
property of the annotation.
Use the 'string' property to change the text string.You may use 'backgroundcolor'
, 'edgecolor'
,'linestyle'
, and 'linewidth'
properties to customizethe box background color and edge appearance. A limited set of text
objects properties are also available; Besides 'font…'
properties, you may also use 'horizontalalignment'
and'verticalalignment'
to position the text inside the box.
Finally, the 'fitboxtotext'
property controls the actual extent ofthe box. If 'on'
(the default) the box limits are fitted to thetext extent.
'rectangle'
Construct a rectangle. pos specifies the 'position'
propertyof the annotation.
You may use 'facecolor'
, 'color'
, 'linestyle'
, and'linewidth'
properties to customize the rectangle background colorand edge appearance.
Plot Legend In R
'ellipse'
Construct an ellipse. pos specifies the 'position'
propertyof the annotation.
Plot Legend Python
See 'rectangle'
annotations for customization.
Plot Legend Mathematica
See also:xlabel, ylabel, zlabel, title, text, gtext, legend, colorbar.
Plot Legend Outside Of Plot Matplotlib
Next: Multiple Plots on One Page, Previous: Three-Dimensional Plots, Up: High-Level Plotting [Contents][Index]