Mapbox Maps vs Geo Maps

BinderScriptNotebook

Summary: This introduction shows the differences between Geo and Mapbox based geographical charts.

Plotly and therefore Plotly.NET supports two different kinds of maps:

  • Mapbox maps are tile-based maps. If your figure is created with a Chart.*Mapbox function or otherwise contains one or more traces of type scattermapbox, choroplethmapbox or densitymapbox, the layout.mapbox object in your figure contains configuration information for the map itself.

  • Geo maps are outline-based maps. If your figure is created with a Chart.ScatterGeo,Chart.PointGeo,Chart.LineGeoorChart.Choroplethfunction or otherwise contains one or more traces of typescattergeoorchoropleth`, the layout.geo object in your figure contains configuration information for the map itself.

This page documents Mapbox tile-based maps, and the [Geo map documentation](https://plotly.net//050geo-vs-mapbox.html) describes how to configure outline-based maps

How Layers Work in Mapbox Tile Maps

Mapbox tile maps are composed of various layers, of three different types:

  • the style property of the Mapbox object defines is the lowest layers, also known as your "base map"
  • The various traces in data are by default rendered above the base map (although this can be controlled via the below attribute).
  • the layers property of the Mapbox object is an array that defines more layers that are by default rendered above the traces in data (although this can also be controlled via the below attribute).

a Mapbox object where these properties can be set can be initialized via Mapbox.init. To use it in a chart, use the Chart.withMapbox function:

open Plotly.NET
open Plotly.NET.LayoutObjects

// a simple Mapbox with a OpenStreetMap base layer.
let mb =
    Mapbox.init(
        Style = StyleParam.MapboxStyle.OpenStreetMap
    )

let baseLayerOnly = 
    Chart.PointMapbox([],[]) // deliberately empty chart to show the base map only
    |> Chart.withMapbox mb // add the mapBox

Mapbox Access Tokens and When You Need Them

The word "mapbox" in the trace names and layout.mapbox refers to the Mapbox GL JS open-source library, which is integrated into Plotly.NET.

If your basemap uses data from the Mapbox service, then you will need to register for a free account at https://mapbox.com/ and obtain a Mapbox Access token.

This token should be provided via the AccessToken property:

let mbWithToken =
    Mapbox.init(
        Style = StyleParam.MapboxStyle.OpenStreetMap,
        AccessToken = "your_token_here"
    )

If your base map does not use data from the Mapbox service, you do not need to register for a Mapbox account.

Base Maps

  • WhiteBG yields an empty white canvas which results in no external HTTP requests
  • The plotly presets yield maps composed of raster tiles from various public tile servers which do not require signups or access tokens
  • The Mapbox presets yield maps composed of vector tiles from the Mapbox service, and do require a Mapbox Access Token or an on-premise Mapbox installation.
  • Use StyleParam.MapboxStyle.Custom for:

The accepted values for the style property of the Mapbox object are represented in StyleParam.MapboxStyle:

type MapboxStyle =
    // plotly presets, no token needed
    | WhiteBG
    | OpenStreetMap
    | CartoPositron
    | CartoDarkmatter
    | StamenTerrain
    | StamenToner
    | StamenWatercolor

    // Mapbox presets, you might need a free token
    | MapboxBasic
    | MapboxStreets
    | MapboxOutdoors
    | MapboxLight
    | MapboxDark
    | MapboxSatellite
    | MapboxSatelliteStreets

    //Custom - provide custom maps
    | Custom of string
namespace Plotly
namespace Plotly.NET
namespace Plotly.NET.LayoutObjects
val mb : Mapbox
Multiple items
type Mapbox = inherit DynamicObj new : unit -> Mapbox static member init : ?Domain:Domain * ?AccessToken:string * ?Style:MapboxStyle * ?Center:(float * float) * ?Zoom:float * ?Bearing:float * ?Pitch:float * ?Layers:seq<MapboxLayer> -> Mapbox static member style : ?Domain:Domain * ?AccessToken:string * ?Style:MapboxStyle * ?Center:(float * float) * ?Zoom:float * ?Bearing:float * ?Pitch:float * ?Layers:seq<MapboxLayer> -> (Mapbox -> Mapbox)
<summary>Determines the style of the map shown in mapbox traces</summary>

--------------------
new : unit -> Mapbox
static member Mapbox.init : ?Domain:Domain * ?AccessToken:string * ?Style:StyleParam.MapboxStyle * ?Center:(float * float) * ?Zoom:float * ?Bearing:float * ?Pitch:float * ?Layers:seq<MapboxLayer> -> Mapbox
module StyleParam from Plotly.NET
type MapboxStyle = | OpenStreetMap | WhiteBG | CartoPositron | CartoDarkmatter | StamenTerrain | StamenToner | StamenWatercolor | MapboxBasic | MapboxStreets | MapboxOutdoors ... member Convert : unit -> obj override ToString : unit -> string static member convert : (MapboxStyle -> obj) static member toString : (MapboxStyle -> string)
<summary> Defines the map layers that are rendered by default below the trace layers defined in `data`, which are themselves by default rendered below the layers defined in `layout.mapbox.layers`. These layers can be defined either explicitly as a Mapbox Style object which can contain multiple layer definitions that load data from any public or private Tile Map Service (TMS or XYZ) or Web Map Service (WMS) or implicitly by using one of the built-in style objects which use WMSes which do not require any access tokens, or by using a default Mapbox style or custom Mapbox style URL, both of which require a Mapbox access token Note that Mapbox access token can be set in the `accesstoken` attribute or in the `mapboxAccessToken` config option. Mapbox Style objects are of the form described in the Mapbox GL JS documentation available at https://docs.mapbox.com/mapbox-gl-js/style-spec The built-in plotly.js styles objects are: open-street-map, white-bg, carto-positron, carto-darkmatter, stamen-terrain, stamen-toner, stamen-watercolor The built-in Mapbox styles are: basic, streets, outdoors, light, dark, satellite, satellite-streets Mapbox style URLs are of the form: mapbox://mapbox.mapbox-&lt;name&gt;-&lt;version&gt; </summary>
union case StyleParam.MapboxStyle.OpenStreetMap: StyleParam.MapboxStyle
val baseLayerOnly : GenericChart.GenericChart
type Chart = static member Area : x:seq<#IConvertible> * y:seq<#IConvertible> * ?Name:string * ?ShowMarkers:bool * ?ShowLegend:bool * ?MarkerSymbol:MarkerSymbol * ?Color:Color * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Dash:DrawingStyle * ?Width:float -> GenericChart + 1 overload static member Bar : values:seq<#IConvertible> * ?Keys:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?PatternShape:PatternShape * ?MultiPatternShape:seq<PatternShape> * ?Pattern:Pattern * ?Base:#IConvertible * ?Width:'a3 * ?MultiWidth:seq<'a3> * ?Opacity:float * ?MultiOpacity:seq<float> * ?Text:'a4 * ?MultiText:seq<'a4> * ?TextPosition:TextPosition * ?MultiTextPosition:seq<TextPosition> * ?TextFont:Font * ?Marker:Marker -> GenericChart (requires 'a3 :> IConvertible and 'a4 :> IConvertible) + 1 overload static member BoxPlot : ?x:'a0 * ?y:'a1 * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Fillcolor:Color * ?Opacity:float * ?Whiskerwidth:'a2 * ?Boxpoints:Boxpoints * ?Boxmean:BoxMean * ?Jitter:'a3 * ?Pointpos:'a4 * ?Orientation:Orientation * ?Marker:Marker * ?Line:Line * ?Alignmentgroup:'a5 * ?Offsetgroup:'a6 * ?Notched:bool * ?NotchWidth:float * ?QuartileMethod:QuartileMethod -> GenericChart + 1 overload static member Bubble : x:seq<#IConvertible> * y:seq<#IConvertible> * sizes:seq<int> * ?Name:string * ?ShowLegend:bool * ?MarkerSymbol:MarkerSymbol * ?Color:Color * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?StackGroup:string * ?Orientation:Orientation * ?GroupNorm:GroupNorm * ?UseWebGL:bool -> GenericChart + 1 overload static member Candlestick : open:seq<#IConvertible> * high:seq<#IConvertible> * low:seq<#IConvertible> * close:seq<#IConvertible> * x:seq<#IConvertible> * ?Increasing:Line * ?Decreasing:Line * ?WhiskerWidth:float * ?Line:Line * ?XCalendar:Calendar -> GenericChart + 1 overload static member Column : values:seq<#IConvertible> * ?Keys:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Pattern:Pattern * ?PatternShape:PatternShape * ?MultiPatternShape:seq<PatternShape> * ?Base:#IConvertible * ?Width:'a3 * ?MultiWidth:seq<'a3> * ?Opacity:float * ?MultiOpacity:seq<float> * ?Text:'a4 * ?MultiText:seq<'a4> * ?TextPosition:TextPosition * ?MultiTextPosition:seq<TextPosition> * ?TextFont:Font * ?Marker:Marker -> GenericChart (requires 'a3 :> IConvertible and 'a4 :> IConvertible) + 1 overload static member Contour : data:seq<#seq<'a1>> * ?X:seq<#IConvertible> * ?Y:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Opacity:float * ?Colorscale:Colorscale * ?Showscale:'a4 * ?zSmooth:SmoothAlg * ?ColorBar:'a5 -> GenericChart (requires 'a1 :> IConvertible) static member Funnel : x:seq<#IConvertible> * y:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Color:Color * ?Line:Line * ?x0:'a3 * ?dX:float * ?y0:'a4 * ?dY:float * ?Width:float * ?Offset:float * ?Orientation:Orientation * ?Alignmentgroup:string * ?Offsetgroup:string * ?Cliponaxis:bool * ?Connector:FunnelConnector * ?Insidetextfont:Font * ?Outsidetextfont:Font -> GenericChart static member Heatmap : data:seq<#seq<'a1>> * ?ColNames:seq<#IConvertible> * ?RowNames:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Opacity:float * ?Colorscale:Colorscale * ?Showscale:'a4 * ?Xgap:'a5 * ?Ygap:'a6 * ?zSmooth:SmoothAlg * ?ColorBar:'a7 * ?UseWebGL:bool -> GenericChart (requires 'a1 :> IConvertible) static member Histogram : data:seq<#IConvertible> * ?Orientation:Orientation * ?Name:string * ?ShowLegend:bool * ?Opacity:float * ?Color:Color * ?HistNorm:HistNorm * ?HistFunc:HistFunc * ?nBinsx:int * ?nBinsy:int * ?Xbins:Bins * ?Ybins:Bins * ?xError:'a1 * ?yError:'a2 -> GenericChart ...
static member Chart.PointMapbox : lonlat:seq<#System.IConvertible * #System.IConvertible> * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Opacity:float * ?Labels:seq<#System.IConvertible> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?Width:float * ?Below:string * ?Connectgaps:bool * ?Fill:StyleParam.Fill * ?Fillcolor:string -> GenericChart.GenericChart
static member Chart.PointMapbox : longitudes:seq<#System.IConvertible> * latitudes:seq<#System.IConvertible> * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Opacity:float * ?Labels:seq<#System.IConvertible> * ?TextPosition:StyleParam.TextPosition * ?TextFont:Font * ?Width:float * ?Below:string * ?Connectgaps:bool * ?Fill:StyleParam.Fill * ?Fillcolor:string -> GenericChart.GenericChart
static member Chart.withMapbox : mapBox:Mapbox * ?Id:StyleParam.SubPlotId -> (GenericChart.GenericChart -> GenericChart.GenericChart)
module GenericChart from Plotly.NET
<summary> Module to represent a GenericChart </summary>
val toChartHTML : gChart:GenericChart.GenericChart -> string
<summary> Converts a GenericChart to it HTML representation. The div layer has a default size of 600 if not specified otherwise. </summary>
val mbWithToken : Mapbox
type MapboxStyle = | WhiteBG | OpenStreetMap | CartoPositron | CartoDarkmatter | StamenTerrain | StamenToner | StamenWatercolor | MapboxBasic | MapboxStreets | MapboxOutdoors ...
union case MapboxStyle.WhiteBG: MapboxStyle
union case MapboxStyle.OpenStreetMap: MapboxStyle
union case MapboxStyle.CartoPositron: MapboxStyle
union case MapboxStyle.CartoDarkmatter: MapboxStyle
union case MapboxStyle.StamenTerrain: MapboxStyle
union case MapboxStyle.StamenToner: MapboxStyle
union case MapboxStyle.StamenWatercolor: MapboxStyle
union case MapboxStyle.MapboxBasic: MapboxStyle
union case MapboxStyle.MapboxStreets: MapboxStyle
union case MapboxStyle.MapboxOutdoors: MapboxStyle
union case MapboxStyle.MapboxLight: MapboxStyle
union case MapboxStyle.MapboxDark: MapboxStyle
union case MapboxStyle.MapboxSatellite: MapboxStyle
union case MapboxStyle.MapboxSatelliteStreets: MapboxStyle
union case MapboxStyle.Custom: string -> MapboxStyle
Multiple items
val string : value:'T -> string
<summary>Converts the argument to a string using <c>ToString</c>.</summary>
<remarks>For standard integer and floating point values the and any type that implements <c>IFormattable</c><c>ToString</c> conversion uses <c>CultureInfo.InvariantCulture</c>. </remarks>
<param name="value">The input value.</param>
<returns>The converted string.</returns>


--------------------
type string = System.String
<summary>An abbreviation for the CLI type <see cref="T:System.String" />.</summary>
<category>Basic Types</category>