Line(s)

Signature

depict.line(y, x=None, source_dataframe=None, width=900, height=400, description='', title='', x_label=None, y_label=None, show_plot=True, color=None, colorbar_type='auto', legend='auto', line_width=1, alpha=1, style='solid', x_axis_type='auto', y_axis_type='auto', x_range=None, y_range=None, fill_between=False, save_path=None, grid_visible=True)

Plot a graph with one-dimensional line(s)

Parameters:
  • y (array-like of dimension 1 or 2) – The y-coordinates for the points of the line(s). If y is 1-d, one line will be drawn, if it is 2-d, a set of lines will be drawn. The values can be either numbers, or dates (datetimes or parsable strings). If a source_dataframe is given, x and y should be column names / keys.
  • x (None, array-like of dimension 1 or 2) – The x-coordinates for the points of the line(s). If None, indexes starting from 0 and adapted to y will be used. If y is 1-d, one line will be drawn, if it is 2-d, a set of lines will be drawn. The values can be either numbers, or dates (datetimes or parsable strings). If a source_dataframe is given, x and y should be column names / keys.
  • source_dataframe (None, Pandas DataFrame or dict) – Input data as Pandas DataFrame or dictionary. If it is a Pandas DataFrame, and x is None, the index of the dataframe is used as x
  • width (int) – The width of the graph, including any axes, titles, etc
  • height (int) – The height of the graph, including any axes, titles, etc
  • description (str) – HTML-formatted text that will be kept bellow the graph. It generally includes metadata, details about the, graphs, etc. It will be kept when the graph is displayed, exported or rendered in a grid with other graphs. If The graph is summed with other graph, their metadata will be concatenated (adding a new line between both)
  • title (str) – Title of the graph. The attributes of the title (font), cannot be tuned directly in depict
  • x_label (None, str) – Label of the x-axis
  • y_label (None, str) – Label of the y-axis
  • show_plot (bool) – Whether or not the graph must be displayed immediatly after its creation
  • color (None, str, array-like) – If None, the first color of the palette is used. If string, a color name is expected (hexadecimal, RGB, and usual colors are accepted), and it will be the same for all the lines. If array-like, the length of color should correspond to the number of lines drawn, they will correspond to each line respectively
  • colorbar_type ({auto, categorical, continuous}) – If ‘auto’, the best type will be chosen wrt the data. If categorical: a legend will be used, not a colorbar. If continuous, a colorbar will be displayed on the right side of the plot. The data defining the color must be passed in color
  • legend ('auto', array-like) – If auto, the legend will be set when a Pandas DataFrame ora dictionary is provided (the name of the columns / keys will be the legend). If array-like, the length of legend must match with the number of curves dranw
  • line_width (Number, array-like) – Width of the line(s). If Number it will the same for all the lines. If it is an array-like, its length must match with the number of lines drawn. They will correspond to each line respectively
  • alpha (Number, array-like) – Alpha value of the line(s). If Number it will the same for all the lines. If it is an array-like, its length must match with the number of lines drawn. They will correspond to each line respectively
  • ({'solid', 'dashed', 'dotted', 'dotdash', dashdot'} or array (style) – like of those): Style of the line(s). If it is an array-like, its length must match with the number of lines drawn. They will correspond to each line respectively
  • x_axis_type ({'auto', 'numerical', 'datetime'}) – Type of the axis. If ‘auto’, the type will be set automatically based on the data provided. If ‘numerical’, ‘datetime’, the type is set accordingly
  • y_axis_type ({'auto', 'numerical', 'datetime'}) – Type of the axis. If ‘auto’, the type will be set automatically based on the data provided. If ‘numerical’, ‘datetime’, the type is set accordingly
  • x_range (array-like) – Range of the x-axis
  • y_range (array-like) – Range of the y-axis
  • fill_between (bool) – If True, there must be at least 2 curves to plot and the area between the first 2 curves is filled. The color of the first line and its alpha value are used for the part filled. In depict, you cannot have more control about this area
  • save_path (None, str) – If None, the graph is not saved. If str, the graph is saved in html at the gicen path. If the html extension is missing, it will be added automatically
  • grid_visible (bool) – Whether the background grid must be displayed. In depict, you cannot have further control about the background grid
Returns:

None

Examples

_images/ex_line_1.png
import depict
import numpy as np

random_walk = np.cumsum(np.random.rand(1000) - 0.5)
zero_line = np.zeros_like(random_walk)
depict.line([random_walk, zero_line], title='Random walk',
            x_label='Step', legend=['Walk', 'Zero'])

_images/ex_line_2.png
import depict
import numpy as np

random_walk = np.cumsum(np.random.rand(1000) - 0.5)
zero_line = np.zeros_like(random_walk)
depict.line([zero_line, random_walk], fill_between=True, color='navy',
            alpha=0.5)

_images/ex_line_3.png
import depict
import numpy as np

random_walk = lambda : np.cumsum(np.random.rand(1000) - 0.5)
zero_line = np.zeros(1000)
p = depict.line([zero_line, random_walk()], fill_between=True, color='navy',
                alpha=0.2, show_plot=False, legend='Random walk 1')
p += depict.line([zero_line, random_walk()], fill_between=True, color='red',
                 alpha=0.2, show_plot=False, legend='Random walk 2')
depict.show(p)

_images/ex_line_4.png
import depict
import numpy as np

y = [np.sin(i * 2 * np.pi * np.linspace(0, 1, 1000)) + 3 * i for i in range(1, 6)]
legend = ['sin({} * 2 * pi) + 3 * {}'.format(i, i) for i in range(1, 6)]
depict.line(x=np.linspace(0, 1, 1000), y=y, color=np.arange(1, 6),
            legend=legend, colorbar_type='categorical')

_images/ex_line_5.png
import depict
import numpy as np

random_walk = np.cumsum(np.random.rand(100) - 0.5)
std = np.std(random_walk)
depict.line([random_walk - std, random_walk + std, random_walk], fill_between=True,
            alpha=0.3, color='navy', style=['solid', 'solid', '-'])