Maps


Maps block.

The Maps chart is a visualization to plot the World and color and mark countries together with circles for highlighs. For demonstration purposes, the “surfspots” can be used. The javascript code is forked from Mike Bostock and then Pythonized.

param df:
Input data containing the following columns:
  • ‘lon’, ‘lat’, ‘label’, ‘size’, ‘opacity’

type df:

pd.DataFrame()

param size:
Size of the nodes:
  • 10 : Same size for all scatter points

  • [10, 4, 30, ..]

type size:

str (default: 10)

param color:
Hex color of the scatter points:
  • ‘#0981D1’: Same color for all scatter points

  • [‘Netherlands’, ‘Australia’, ‘Austrialia’, ..]

  • [‘#000FFF’, ‘#000000’, ‘#000000’, ..]

type color:

str (default: ‘#0981D1’)

param opacity:
Opacity of the scatter points:
  • 0.8 : Same opacity for all scatter points

  • [0.8, 0.6, ..]

type opacity:

str (default: 0.8)

param label:
Label of the scatter points:
  • ‘’ : Same label for all scatter points

  • [‘Amsterdam’, ‘New York’, ..]

type label:

str (default: ‘’)

param countries:
border properties of the countries. The world are the properties of the entire map. Each country can be changed accordingly.
  • {‘World’: {‘color’:’#D3D3D3’, ‘opacity’: 0.3, ‘line’: ‘none’, ‘linewidth’: 1}},

  • color: color for the country

  • opacity: opacity of the country

  • line: [‘dashed’, ‘none’], line of the country

  • linewidth: width of the line

type countries:

dict.

param title:
Title of the figure.
  • ‘Circlepacking’

type title:

String, (default: None)

param filepath:
  • File path to save the output.

  • Temporarily path: ‘d3blocks.html’

  • Relative path: ‘./d3blocks.html’

  • Absolute path: ‘c://temp//d3blocks.html’

  • None: Return HTML

type filepath:

String, (Default: user temp directory)

param figsize:
Size of the figure in the browser, [width, height].
  • [1000, 1200]

  • None or [None, None]: Use the screen resolution.

type figsize:

tuple

param showfig:
  • True: Open browser-window.

  • False: Do not open browser-window.

type showfig:

bool, (default: True)

param overwrite:
  • True: Overwrite the html in the destination directory.

  • False: Do not overwrite destination file but show warning instead.

type overwrite:

bool, (default: True)

param notebook:
  • True: Use IPython to show chart in notebook.

  • False: Do not use IPython.

type notebook:

bool

param save_button:
  • True: Save button is shown in the HTML to save the image in svg.

  • False: No save button is shown in the HTML.

type save_button:

bool, (default: True)

param reset_properties:
  • True: Reset the node_properties at each run.

  • False: Use the d3.node_properties()

type reset_properties:

bool, (default: True)

returns:
  • d3.node_properties (DataFrame of dictionary) – Contains properties of the unique input label/nodes/samples.

  • d3.edge_properties (DataFrame of dictionary) – Contains properties of the unique input edges/links.

  • d3.config (dictionary) – Contains configuration properties.

Examples

>>> # Load d3blocks
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Load example data
>>> df = d3.import_example('surfspots')
>>> #
>>> # Plot
>>> d3.maps(df)
>>> #

Examples

>>> # Load d3blocks
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks()
>>> #
>>> # Load example data
>>> df = d3.import_example('surfspots')
>>> #
>>> # Plot
>>> d3.maps(df, color=df['label'].values, cmap='Set2')
>>> #
>>> html = d3.maps(df, color=df['label'].values, countries = {'World': {'color':'#D3D3D3', 'opacity': 0.4, 'line': 'none', 'linewidth': 0.1},
>>>                                                                 'Netherlands': {'color': '#000FFF', 'opacity': 0.5, 'line': 'none', 'linewidth': 1},
>>>                                                                 'France': {'color': '#FFA500', 'opacity': 1, 'line': 'dashed', 'linewidth': 2},
>>>                                                                 'Australia': {'color': '#008000', 'opacity': 0.3, 'line': 'dashed', 'linewidth': 5},
>>>                                                                 })

Examples

>>> # Load library
>>> from d3blocks import D3Blocks
>>> #
>>> # Initialize
>>> d3 = D3Blocks(chart='maps', frame=False)
>>> #
>>> # Import example
>>> df = d3.import_example('surfspots', overwrite=True)
>>> #
>>> # Set node properties
>>> d3.set_node_properties(df)
>>> d3.node_properties
>>> #
>>> # Set edge properties
>>> d3.set_edge_properties({'Australia': {'color': '#008000', 'opacity': 0.3, 'line': 'dashed', 'linewidth': 5},
>>>                         'Netherlands': {'color': '#000FFF', 'line': 'dashed'},
>>>                         })
>>> d3.edge_properties
>>> #
>>> # Show chart
>>> d3.show()
>>> #

Input Data

The input dataset is a DataFrame that contains the lat and lon coordinates. More features can be added such as label, size opacity.

#        lat    lon          label  size
# 0    -82.9  135.0     Antarctica     4
# 1    -54.8  -68.3  South America     4
# 2    -53.8  -67.7  South America     1
# 3    -53.2  -70.9            NaN     2
# 4    -52.4  -71.0  South America     2
#    ...    ...            ...   ...
# 9408  69.6   19.0            NaN     1
# 9409  70.0   23.3         Europe     1
# 9410  70.4   29.5         Europe    13
# 9411  76.3 -100.1  North America     1
# 9412  78.2   15.6         Europe     3

Charts