MATLAB Examples

# Graphic Scales

This example shows how to add graphic scales to maps and how to modify the display properties of graphic scales.

Graphic scale elements are used to provide indications of size even more frequently than insets are. These are ruler-like objects that show distances on the ground at the nominal scale of the projection. You can use the scaleruler function to add a graphic scale to the current map. You can check and modify the scaleruler settings using getm and setm. You can also move the graphic scale to a new position by dragging its baseline.

Use usamap to plot a map of Texas and surrounding states as filled polygons.

```states = shaperead('usastatehi.shp', 'UseGeoCoords', true); figure usamap('Texas') faceColors = makesymbolspec('Polygon',... {'INDEX', [1 numel(states)], ... 'FaceColor', polcmap(numel(states))}); geoshow(states,'DisplayType', 'polygon', ... 'SymbolSpec', faceColors) ```

Because polcmap randomizes patch colors, your display can look different.

Add a default graphic scale and then move it to a new location.

```scaleruler on setm(handlem('scaleruler1'), ... 'XLoc',-6.2e5,'YLoc',3.1e6, ... 'MajorTick',0:200:600) ```

The units of scaleruler default to kilometers. Note that handlem accepts the keyword 'scaleruler' or 'scaleruler1' for the first scaleruler, 'scaleruler2' for the second one, etc. If there is more than one scaleruler on the current axes, specifying the keyword 'scaleruler' returns a vector of handles.

Obtain a handle to the scaleruler's hggroup using handlem and inspect its properties using getm.

```s = handlem('scaleruler'); getm(s) ```
```ans = struct with fields: Azimuth: 0 Children: [] Color: [0 0 0] FontAngle: 'normal' FontName: 'Helvetica' FontSize: 9 FontUnits: 'points' FontWeight: 'normal' Label: '' Lat: 29.6479 Long: -101.7263 LineWidth: 0.5000 MajorTick: [0 200 400 600] MajorTickLabel: {4x1 cell} MajorTickLength: 20 MinorTick: [0 25 50 75 100] MinorTickLabel: '100' MinorTickLength: 12.5000 Radius: 'earth' RulerStyle: 'ruler' TickDir: 'up' TickMode: 'manual' Units: 'km' XLoc: -620000 YLoc: 3100000 ZLoc: [] ```

Change the scaleruler's font size to 8 points.

```setm(s,'fontsize',8) ```

Place a second graphic scale, this one in units of nautical miles.

```scaleruler('units','nm') ```

Modify the tick properties of the second graphic scale.

```setm(handlem('scaleruler2'), 'YLoc', 3.0e6, ... 'MajorTick', 0:100:300,... 'MinorTick', 0:25:50, 'TickDir', 'down', ... 'MajorTickLength', km2nm(25),... 'MinorTickLength', km2nm(12.5)) ```

Experiment with the two other ruler styles available.

```setm(handlem('scaleruler1'), 'RulerStyle', 'lines') setm(handlem('scaleruler2'), 'RulerStyle', 'patches') ```