Download notebook (.ipynb)

Customizing Line Type#

A new way to specify the linetype:

  • list, defining the pattern of dashes and gaps used to draw the line: [dash, gap, ...];

  • list with specified offset: [offset, [dash, gap, ...]];

  • string of an even number (up to eight) of hexadecimal digits which give the lengths in consecutive positions in the string.

from lets_plot import *
from lets_plot import tilesets
LetsPlot.setup_html()
def plot_linetypes(line_types):
    n = len(line_types)
    data = {
        'x': [0] * n,
        'xend': [1] * n,
        'y': line_types,
        'yend': line_types,
        'linetype': line_types
    }
    return ggplot(data) + \
            geom_segment(aes(x='x', xend='xend', y='y', yend='yend',
                         linetype='linetype'),
                         tooltips='none') + \
            scale_linetype_identity()

Use Dash Arrays#

line_types = [
    [1, 1],               # dotted
    [5, 5],               # dashed
    [10, 5],              # long dashed
    [5, [10, 5]],         # long dashed with offset
    [5, 10, 1, 10],       # dashdotted
    [10, 5, 1, 5, 1, 5],  # dashdotdotted
]

plot_linetypes(line_types)

Use String of HEX Digits#

hex_line_types = [
    "11",
    "55",
    "A5",
    "5A1A"
]

plot_linetypes(hex_line_types)

Use in element_line()#

ggplot() + \
    geom_blank() + \
    theme_bw() + \
    theme(panel_grid = element_line(linetype=[5, [10, 5]], color='grey'))

On livemap#

data = {
    'lon': [-73.7997, 14.418540],
    'lat': [40.6408, 50.073658],
}
ggplot(data, aes(x='lon', y='lat')) + \
    geom_livemap(tiles=tilesets.LETS_PLOT_DARK) + \
    geom_path(geodesic=True, color='white', linetype=[5, [10, 5]])