# geodensityplot

Density plot in geographic coordinates

## Syntax

``geodensityplot(lat,lon)``
``geodensityplot(lat,lon,weights)``
``geodensityplot(gx,___)``
``geodensityplot(___,Name=Value)``
``dp = geodensityplot(___)``

## Description

````geodensityplot(lat,lon)` creates a density plot in geographic coordinates. Specify the latitude coordinates in degrees using `lat`, and specify the longitude coordinates in degrees using `lon`. If the current axes is not a geographic axes, or if there is no current axes, then the function creates the density plot in a new geographic axes. ```

example

````geodensityplot(lat,lon,weights)` specifies weights for the data points.```

example

````geodensityplot(gx,___)` plots into the geographic axes specified by `gx`. Specify the axes as the first argument followed by any of the input argument combinations in the previous syntaxes.```
````geodensityplot(___,Name=Value)` specifies properties of the density plot using one or more name-value arguments. For a list of properties, see DensityPlot Properties. ```

example

````dp = geodensityplot(___)` returns the `DensityPlot` object. Use `dp` to set properties after creating the plot. For a full list of properties, see DensityPlot Properties. ```

## Examples

collapse all

Load a table containing cell tower data for California. Each table row represents a cell tower. The table variables include data about the cell towers, such as the latitude and longitude coordinates. Extract the latitude and longitude coordinates from the table.

```load cellularTowers.mat lat = cellularTowers.Latitude; lon = cellularTowers.Longitude;```

Create a density plot from the coordinates. By default, the `geodensityplot` function visualizes density by varying the transparency of the plot. Regions with high density are more opaque, and regions with low density are more transparent.

```figure geodensityplot(lat,lon)```

Load a table containing cyclone track data. The table includes the locations and wind speeds of over 200 cyclones, measured at six-hour intervals. Extract the latitude coordinates, the longitude coordinates, and the wind speeds from the table.

```load cycloneTracks.mat lat = cycloneTracks.Latitude; lon = cycloneTracks.Longitude; windspeed = cycloneTracks.WindSpeed;```

Create a density plot from the coordinates, and weight the points using the wind speeds. The resulting density plot highlights the areas where the cyclones have the highest wind speeds.

`geodensityplot(lat,lon,windspeed)`

This example uses modified RSMC Best Track Data from the Japan Meteorological Agency.

Load a table containing cell tower data for California. Each table row represents a cell tower. The table variables include data about the cell towers, such as the latitude and longitude coordinates. Extract the latitude and longitude coordinates from the table.

```load cellularTowers.mat lat = cellularTowers.Latitude; lon = cellularTowers.Longitude;```

Create a density plot from the coordinates. Specify the radius of influence for each point as 50 km.

`geodensityplot(lat,lon,Radius=50e3)`

By default, the `geodensityplot` function visualizes density by varying the transparency of the density plot. You can also visualize density by varying the plot colors.

Load a table containing cyclone track data. The table records the tracks of over 200 cyclones, measured at six-hour intervals. Extract the latitude and longitude coordinates from the table.

```load cycloneTracks.mat lat = cycloneTracks.Latitude; lon = cycloneTracks.Longitude;```

Create a density plot from the coordinates. Vary the plot colors by setting the `FaceColor` property to `"interp"`.

`geodensityplot(lat,lon,FaceColor="interp")`

Change the colormap, and add a labeled color bar. When you do not weight the data, the units of the density plot are points per square meter. Note that the plot visualizes the density using both transparency and color.

```colormap turbo c = colorbar; c.Label.String = "Data points per square meter";```

This example uses modified RSMC Best Track Data from the Japan Meteorological Agency.

## Input Arguments

collapse all

Latitude coordinates in degrees, specified as a vector with elements in the range [–90, 90]. The vector can contain `NaN` values.

The sizes of `lat` and `lon` must match.

Example: `[43.0327 38.8921 44.0435]`

Data Types: `single` | `double`

Longitude coordinates in degrees, specified as a vector. The vector can contain `NaN` values.

The sizes of `lat` and `lon` must match.

Example: `[-107.5556 -77.0269 -72.5565]`

Data Types: `single` | `double`

Weights assigned to the data, specified as a numeric scalar, a numeric vector, or an empty array (`[]`). If you specify a vector, the size of the vector must match the sizes of `lat` and `lon`.

This argument typically specifies additional data that is related to the location data in `lat` and `lon`.

Target geographic axes, specified as a `GeographicAxes` object.1 You can modify the appearance and behavior of a `GeographicAxes` object by setting its properties. For a list of properties, see GeographicAxes Properties.

If you do not specify this argument, then the function plots into the current axes, provided that the current axes is a geographic axes. If the current axes is not a geographic axes, or if there is no current axes, then the function plots into a new geographic axes.

### Name-Value Arguments

Specify optional pairs of arguments as `Name1=Value1,...,NameN=ValueN`, where `Name` is the argument name and `Value` is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: `geodensityplot(lat,lon,FaceColor="g")` sets the face color of the density plot to green.

Before R2021a, use commas to separate each name and value, and enclose `Name` in quotes.

Example: `geodensityplot(lat,lon,"FaceColor","g")` sets the face color of the density plot to green.

Note

Use name-value arguments to specify values for the properties of the `DensityPlot` object created by this function. The properties listed here are only a subset. For a full list, see DensityPlot Properties.

Radius of influence on the density calculation, in meters, specified as a numeric scalar.

Face transparency, specified as one of these values:

• `'interp'` — Use interpolated transparency based on the density values.

• Scalar in the range [0, 1] — Use uniform transparency across all the faces. A value of `1` is opaque and a value of `0` is completely transparent. Values between `0` and `1` are semitransparent.

The appearance of the density plot depends on both the `FaceAlpha` and `FaceColor` properties. This table shows how different combinations of `FaceAlpha` and `FaceColor` affect the appearance of the plot.

Values of `FaceColor` and `FaceAlpha`EffectSample Density Plot
• `FaceAlpha` is `"interp"`

• `FaceColor` is an RGB triplet, a hexadecimal color code, a color name, or a short name

The density plot uses one color and conveys density by varying the transparency.

• `FaceAlpha` is `"interp"`

• `FaceColor` is `"interp"`

The density plot conveys density by varying the transparency and the color.

• `FaceAlpha` is a scalar value

• `FaceColor` is `"interp"`

The density plot uses one transparency value and conveys density by varying the color.

Face color, specified as one of these options:

• `'interp'` — Use interpolated coloring based on the density values. MATLAB® chooses colors from the colormap of the parent axes. When you choose this option, the appearance of the density plot also depends on the value of the `FaceAlpha` property. For more information, see the `FaceAlpha` property.

• An RGB triplet, a hexadecimal color code, a color name, or a short name — Apply one color to the density plot. When you choose this option, the value of `FaceAlpha` must be `"interp"`.

RGB triplets and hexadecimal color codes are useful for specifying custom colors.

• An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range `[0,1]`; for example,``` [0.4 0.6 0.7]```.

• A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol (`#`) followed by three or six hexadecimal digits, which can range from `0` to `F`. The values are not case sensitive. Thus, the color codes `"#FF8800"`, `"#ff8800"`, `"#F80"`, and `"#f80"` are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
`"red"``"r"``[1 0 0]``"#FF0000"`

`"green"``"g"``[0 1 0]``"#00FF00"`

`"blue"``"b"``[0 0 1]``"#0000FF"`

`"cyan"` `"c"``[0 1 1]``"#00FFFF"`

`"magenta"``"m"``[1 0 1]``"#FF00FF"`

`"yellow"``"y"``[1 1 0]``"#FFFF00"`

`"black"``"k"``[0 0 0]``"#000000"`

`"white"``"w"``[1 1 1]``"#FFFFFF"`

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB uses in many types of plots.

`[0 0.4470 0.7410]``"#0072BD"`

`[0.8500 0.3250 0.0980]``"#D95319"`

`[0.9290 0.6940 0.1250]``"#EDB120"`

`[0.4940 0.1840 0.5560]``"#7E2F8E"`

`[0.4660 0.6740 0.1880]``"#77AC30"`

`[0.3010 0.7450 0.9330]``"#4DBEEE"`

`[0.6350 0.0780 0.1840]``"#A2142F"`

## Tips

When you plot on geographic axes, the `geodensityplot` function assumes that coordinates are referenced to the WGS84 coordinate reference system. If you plot using coordinates that are referenced to a different coordinate reference system, then the coordinates might appear misaligned.

## Algorithms

A density plot is a surface with varying transparency. The `geodensityplot` function creates the surface by calculating a cumulative probability distribution from the specified points and varying the transparency with the density of the points.

By default, each point contributes equally to the density plot. When you weight the points, the function multiplies the contribution of the associated points to the density plot.

## Version History

Introduced in R2018b

expand all