Next: Multiple Plots on One Page, Previous: Three-Dimensional Plots, Up: High-Level Plotting [Contents][Index]
I am trying to omit the legend entry for graph b, but the following code still shows the curve in the legend.
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. A list specifying aesthetic parameters of legend key. See details and examples. Nrow: The desired number of rows of legends. Ncol: The desired number of column of legends. If FALSE (the default) the legend-matrix is filled by columns, otherwise the legend-matrix is filled by rows. Reverse: logical. If TRUE the order of legends. 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. When we want to put legend somewhere in a figure using Matplotlib, most of the time, the option loc='best' will produce the desired results. However, sometimes, we may want to have finer control over where the legend should be in the image. For example, we may want to put the legend outside of the axes, which is impossible using loc='best'.
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'
Slots berlin casino. 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. Ocasio cortez and 4 friends.
'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:
Plot Legend Matplotlib
'line'
Constructs a line. x and y must be two-element vectorsspecifying the x and y coordinates of the two ends of the line.
Plot Legend Color
The line can be customized using 'linewidth'
, 'linestyle'
,and 'color'
properties the same way as for line
objects.
'arrow'
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.
'ellipse'
Construct an ellipse. pos specifies the 'position'
propertyof the annotation.
See 'rectangle'
annotations for customization.
See also:xlabel, ylabel, zlabel, title, text, gtext, legend, colorbar.
Next: Multiple Plots on One Page, Previous: Three-Dimensional Plots, Up: High-Level Plotting [Contents][Index]