Maps


D3Blocks.maps(df, size=10, color='#0981D1', opacity=0.8, label='', countries={'Australia': {'color': '#008000', 'line': 'dashed', 'linewidth': 5, 'opacity': 0.3}, 'World': {'color': '#D3D3D3', 'line': 'none', 'linewidth': 1, 'opacity': 0.6}}, cmap='Set2', title: str = 'Maps - D3blocks', filepath: str = 'maps.html', figsize=None, showfig: bool = True, overwrite: bool = True, notebook: bool = False, save_button: bool = True, return_html: bool = False, reset_properties: bool = True)

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.

Parameters:
  • df (pd.DataFrame()) –

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

  • size (str (default: 10)) –

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

    • [10, 4, 30, ..]

  • color (str (default: '#0981D1')) –

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

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

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

  • opacity (str (default: 0.8)) –

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

    • [0.8, 0.6, ..]

  • label (str (default: '')) –

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

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

  • countries (dict.) –

    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

  • title (String, (default: None)) –

    Title of the figure.
    • ’Circlepacking’

  • filepath (String, (Default: user temp directory)) –

    • File path to save the output.

    • Temporarily path: ‘d3blocks.html’

    • Relative path: ‘./d3blocks.html’

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

    • None: Return HTML

  • figsize (tuple) –

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

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

  • showfig (bool, (default: True)) –

    • True: Open browser-window.

    • False: Do not open browser-window.

  • overwrite (bool, (default: True)) –

    • True: Overwrite the html in the destination directory.

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

  • notebook (bool) –

    • True: Use IPython to show chart in notebook.

    • False: Do not use IPython.

  • save_button (bool, (default: True)) –

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

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

  • return_html (bool, (default: False)) –

    • True: Return html

    • False: Nothing is returned

  • reset_properties (bool, (default: True)) –

    • True: Reset the node_properties at each run.

    • False: Use the d3.node_properties()

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