Skip to content

Plot(*arguments, **keyword_arguments) Source

A drawn view of a Table or an Array, made by creation methods such as Plot.line.

A Plot is immutable: it keeps the values it was made from, so changing the data afterwards never changes it. It is only displayed by show, never on its own in a notebook.

Calling ndp.Plot(...) is refused with RefusedOperationError, which names the methods to use instead.

Added in version 0.1.0

Examples:

import numdaplot as ndp

prices = ndp.Array.from_list([12.0, 15.5, 14.0, 17.0])
plot = ndp.Plot.line(prices)
plot.show()

Plot drawn by the example

Series creation

line(data, chart=None, style=None) Source

Return a Plot drawing columns of numbers or times of day as lines.

For a Table, LineChart.y names the columns drawn and LineChart.x the column of the positions. For an Array of one or two dimensions, each column is a line and each row is placed at its number.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array drawn.

  • chart (LineChart | None, default: None)

    The columns drawn and the look of the lines. The default LineChart when omitted, which draws an Array: a Table needs the columns named.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Examples:

import numdaplot as ndp

days = ndp.Array.from_list([1, 2, 3, 4, 5])
prices = ndp.Array.from_list([12.0, 15.5, 14.0, 17.0, 16.0])
costs = ndp.Array.from_list([8.0, 9.5, 9.0, None, 10.5])
sales = ndp.Table.from_arrays({"day": days, "price": prices, "cost": costs})
chart = ndp.LineChart(x="day", y=["price", "cost"], marker=ndp.MarkerShape.CIRCLE)
style = ndp.PlotStyle(title="Sales", y_label="Euros")
plot = ndp.Plot.line(sales, chart, style)
plot.show()

Plot drawn by the example

bar(data, chart=None, style=None) Source

Return a Plot drawing columns of numbers as bars.

For a Table, BarChart.y names the columns drawn and BarChart.x the column labeling the bars. For an Array of one or two dimensions, each column is a series of bars and each row is labeled with its number.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array drawn.

  • chart (BarChart | None, default: None)

    The columns drawn and the look of the bars. The default BarChart when omitted, which draws an Array: a Table needs the columns named.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Pau", "Nice"])
sales_2025 = ndp.Array.from_list([120.0, 80.0, 45.0, 60.0])
sales_2026 = ndp.Array.from_list([150.0, 95.0, 40.0, 70.0])
sales = ndp.Table.from_arrays({"city": cities, "2025": sales_2025, "2026": sales_2026})
chart = ndp.BarChart(x="city", y=["2025", "2026"], layout=ndp.BarLayout.STACKED)
style = ndp.PlotStyle(title="Sales per city", y_label="Thousands of euros")
plot = ndp.Plot.bar(sales, chart, style)
plot.show()

Plot drawn by the example

scatter(data, chart=None, style=None) Source

Return a Plot drawing each row as a point.

For a Table, ScatterChart.y names the column of the vertical positions and ScatterChart.x the column of the horizontal ones, and the points can be colored and sized by other columns. For an Array of one or two dimensions, each column is a series of points and each row is placed at its number.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array drawn.

  • chart (ScatterChart | None, default: None)

    The columns drawn and the look of the points. The default ScatterChart when omitted, which draws an Array: a Table needs the columns named.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Examples:

import numdaplot as ndp

surfaces = ndp.Array.from_list([30.0, 45.0, 60.0, 80.0, 52.0, 38.0])
prices = ndp.Array.from_list([150.0, 210.0, 260.0, 330.0, 190.0, 160.0])
rooms = ndp.Array.from_list([1, 2, 3, 4, 3, 2])
flats = ndp.Table.from_arrays({"surface": surfaces, "price": prices, "rooms": rooms})
chart = ndp.ScatterChart(x="surface", y="price", color_by="rooms")
style = ndp.PlotStyle(x_label="Surface (m2)", y_label="Price (thousands of euros)")
plot = ndp.Plot.scatter(flats, chart, style)
plot.show()

Plot drawn by the example

Distribution creation

histogram(data, chart=None, style=None) Source

Return a Plot drawing how many values of columns of numbers or times of day fall in each bin.

For a Table, HistogramChart.columns names the columns drawn. For an Array of one or two dimensions, each column is drawn. Several columns share the same bins.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array drawn.

  • chart (HistogramChart | None, default: None)

    The columns drawn, the bins, the measure and the colors. The default HistogramChart when omitted, which draws an Array: a Table needs the columns named.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Examples:

import numdaplot as ndp

prices = ndp.Array.from_list([12.0, 15.5, 14.0, 17.0, 13.5, 16.0, 14.5, 15.0, 18.5, 11.0])
flats = ndp.Table.from_arrays({"price": prices})
chart = ndp.HistogramChart(columns=["price"], bins=ndp.BinWidth(2.0), measure=ndp.Measure.RATIO)
style = ndp.PlotStyle(title="Prices", x_label="Price (euros)")
plot = ndp.Plot.histogram(flats, chart, style)
plot.show()

Plot drawn by the example

box(data, chart=None, style=None) Source

Return a Plot summing up the spread of columns of numbers or times of day as boxes.

For a Table, BoxChart.columns names the columns drawn, and BoxChart.group_by may split their rows into groups. For an Array of one or two dimensions, each column is a box.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array drawn.

  • chart (BoxChart | None, default: None)

    The columns drawn, their groups, the outliers and the colors. The default BoxChart when omitted, which draws an Array: a Table needs the columns named.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Pau", "Paris", "Lyon", "Pau", "Paris", "Lyon", "Pau"])
prices = ndp.Array.from_list([14.0, 9.5, 7.0, 16.5, 10.0, 8.5, 15.0, 11.5, 6.0])
flats = ndp.Table.from_arrays({"city": cities, "price": prices})
chart = ndp.BoxChart(columns=["price"], group_by="city")
style = ndp.PlotStyle(y_label="Price per night (euros)")
plot = ndp.Plot.box(flats, chart, style)
plot.show()

Plot drawn by the example

pie(table, chart, style=None) Source

Return a Plot sharing out the values of a column of a Table as slices of a disc.

PieChart.labels names the column of texts labeling the slices and PieChart.values the column of numbers sizing them. A Plot of a pie has no axes, so its style takes no axis label.

Added in version 0.1.0

Parameters:

  • table (Table)

    The Table drawn.

  • chart (PieChart)

    The labels, the values, the percentages and the colors.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Warns:

Examples:

import numdaplot as ndp

devices = ndp.Array.from_list(["Phone", "Computer", "Tablet"])
visits = ndp.Array.from_list([5400.0, 3100.0, 900.0])
traffic = ndp.Table.from_arrays({"device": devices, "visits": visits})
chart = ndp.PieChart(labels="device", values="visits")
style = ndp.PlotStyle(title="Visits per device")
plot = ndp.Plot.pie(traffic, chart, style)
plot.show()

Plot drawn by the example

Overview creation

heatmap(data, chart=None, style=None) Source

Return a Plot coloring each value of columns of numbers along a color scale.

For a Table, HeatmapChart.columns names the columns drawn and HeatmapChart.labels the column labeling the rows. For an Array of one or two dimensions, each column is drawn and each row is labeled with its number. When there are more rows or columns than the image can show, each band shows the mean of its cells, without their values written, with a ReadabilityWarning.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array drawn.

  • chart (HeatmapChart | None, default: None)

    The columns drawn, the row labels, the color scale and the cell values. The default HeatmapChart when omitted, which draws an Array: a Table needs the columns named.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Warns:

Examples:

import numdaplot as ndp

days = ndp.Array.from_list(["Mon", "Tue", "Wed", "Thu", "Fri"])
morning = ndp.Array.from_list([12.0, 15.0, 9.0, 14.0, 20.0])
noon = ndp.Array.from_list([30.0, 28.0, 25.0, 33.0, 41.0])
evening = ndp.Array.from_list([18.0, 22.0, None, 19.0, 35.0])
orders = ndp.Table.from_arrays({"day": days, "morning": morning, "noon": noon, "evening": evening})
chart = ndp.HeatmapChart(columns=["morning", "noon", "evening"], labels="day", values=ndp.CellValues.SHOWN)
style = ndp.PlotStyle(title="Orders")
plot = ndp.Plot.heatmap(orders, chart, style)
plot.show()

Plot drawn by the example

missing_by_column(table, chart=None, style=None) Source

Return a Plot drawing one bar per column of a Table, as high as its missing values.

Above each bar are its number of missing values and their share of the rows, written on one line going upwards when the bars are too narrow, and left out when they are too narrow for that.

Added in version 0.1.0

Parameters:

  • table (Table)

    The Table whose missing values are counted.

  • chart (MissingChart | None, default: None)

    The measure, the number of missing values of each column when omitted.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Nice", "Pau", "Lyon"])
prices = ndp.Array.from_list([12.0, None, None, 15.5, None])
surfaces = ndp.Array.from_list([30.0, 45.0, None, 60.0, 52.0])
flats = ndp.Table.from_arrays({"city": cities, "price": prices, "surface": surfaces})
style = ndp.PlotStyle(title="Missing values")
plot = ndp.Plot.missing_by_column(flats, style=style)
plot.show()

Plot drawn by the example

missing_map(table, style=None) Source

Return a Plot drawing each value of a Table as a cell, light gray when present and dark when missing.

The columns are side by side and the rows go down from the first one, which shows whether the missing values gather in some rows or columns. When there are more rows or columns than the image can show, each mark stands for at least one missing value among the cells it covers, so no missing value is lost. The legend gives the total of missing values.

Added in version 0.1.0

Parameters:

  • table (Table)

    The Table whose missing values are drawn.

  • style (PlotStyle | None, default: None)

    The look of the Plot, the default PlotStyle when omitted.

Returns:

  • Self

    The Plot, which show displays and save writes as an image.

Raises:

Examples:

import numdaplot as ndp

cities = ndp.Array.from_list(["Paris", "Lyon", "Nice", "Pau", "Lyon", "Nice", "Paris", "Pau"])
prices = ndp.Array.from_list([12.0, None, None, 15.5, None, 18.0, 11.0, 14.0])
surfaces = ndp.Array.from_list([30.0, 45.0, None, 60.0, 52.0, 41.0, None, 38.0])
flats = ndp.Table.from_arrays({"city": cities, "price": prices, "surface": surfaces})
style = ndp.PlotStyle(legend=ndp.LegendPosition.OUTSIDE_RIGHT)
plot = ndp.Plot.missing_map(flats, style)
plot.show()

Plot drawn by the example

Charts over a Plot

add_line(data, chart=None, axis=ValueAxis.LEFT) Source

Return a new Plot with lines added over the charts of this one.

The lines take the colors of the default cycle after the ones already used. Over bars or texts, their x values are placed on the labels of the Plot, new labels following the others.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array of the lines, which may differ from the one of the Plot.

  • chart (LineChart | None, default: None)

    The columns drawn and the look of the lines. The default LineChart when omitted, which draws an Array: a Table needs the columns named.

  • axis (ValueAxis, default: ValueAxis.LEFT)

    ValueAxis.LEFT by default to share the scale of the Plot, ValueAxis.RIGHT for a scale of their own on the right.

Returns:

  • Self

    A new Plot; this one is left unchanged.

Raises:

  • InvalidTypeError

    When an argument is not of the type its annotation names.

  • RefusedSettingError

    When the Plot does not draw lines, vertical bars or points.

  • IncompatibleChartsError

    When the x values are not of the kind of the ones of the Plot: numbers, dates, texts or times of day; or when one measures numbers and the other times of day on the same axis.

  • DuplicateLabelError

    When a label appears twice in the x values of one chart placed on labels.

  • InvalidChartDataError

    When a Table has no y columns, or an Array has x or y columns.

  • InvalidColorCountError

    When the colors of the chart are not one per line.

Examples:

import numdaplot as ndp

months = ndp.Array.from_list(["Jan", "Feb", "Mar", "Apr"])
sales = ndp.Array.from_list([120.0, 150.0, 90.0, 170.0])
targets = ndp.Array.from_list([130.0, 130.0, 140.0, 140.0])
shop = ndp.Table.from_arrays({"month": months, "sales": sales, "target": targets})
plot = ndp.Plot.bar(shop, ndp.BarChart(x="month", y=["sales"]))
line = ndp.LineChart(x="month", y=["target"], marker=ndp.MarkerShape.CIRCLE)
both = plot.add_line(shop, line)
both.show()

Plot drawn by the example

add_bar(data, chart=None, axis=ValueAxis.LEFT) Source

Return a new Plot with vertical bars added over the charts of this one.

The bars are drawn over the ones already there, at the same positions: to draw bars side by side, give several columns to a single BarChart. Their x values are placed on the labels of the Plot, new labels following the others.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array of the bars, which may differ from the one of the Plot.

  • chart (BarChart | None, default: None)

    The columns drawn and the look of the bars, which must be vertical. The default BarChart when omitted, which draws an Array: a Table needs the columns named.

  • axis (ValueAxis, default: ValueAxis.LEFT)

    ValueAxis.LEFT by default to share the scale of the Plot, ValueAxis.RIGHT for a scale of their own on the right.

Returns:

  • Self

    A new Plot; this one is left unchanged.

Raises:

  • InvalidTypeError

    When an argument is not of the type its annotation names.

  • RefusedSettingError

    When the bars are horizontal, or the Plot does not draw lines, vertical bars or points.

  • IncompatibleChartsError

    When the x values are not of the kind of the ones of the Plot: numbers, dates, texts or times of day; or when one measures numbers and the other times of day on the same axis.

  • DuplicateLabelError

    When a label appears twice in the x values of one chart.

  • InvalidChartDataError

    When a Table has no y columns, or an Array has x or y columns.

  • InvalidColorCountError

    When the colors of the chart are not one per series.

Examples:

import numdaplot as ndp

months = ndp.Array.from_list(["Jan", "Feb", "Mar", "Apr"])
sales = ndp.Array.from_list([120.0, 150.0, 90.0, 170.0])
targets = ndp.Array.from_list([130.0, 130.0, 140.0, 160.0])
shop = ndp.Table.from_arrays({"month": months, "sales": sales, "target": targets})
plot = ndp.Plot.bar(shop, ndp.BarChart(x="month", y=["target"], colors=[ndp.CustomColor("#d9d9d9")]))
bars = ndp.BarChart(x="month", y=["sales"], colors=[ndp.Color.BLUE])
both = plot.add_bar(shop, bars)
both.show()

Plot drawn by the example

add_scatter(data, chart=None, axis=ValueAxis.LEFT) Source

Return a new Plot with points added over the charts of this one.

The points take the color of the default cycle after the ones already used, unless color or color_by is given. Over bars or texts, their x values are placed on the labels of the Plot.

Added in version 0.1.0

Parameters:

  • data (Table | Array)

    The Table or the Array of the points, which may differ from the one of the Plot.

  • chart (ScatterChart | None, default: None)

    The columns drawn and the look of the points. The default ScatterChart when omitted, which draws an Array: a Table needs the columns named.

  • axis (ValueAxis, default: ValueAxis.LEFT)

    ValueAxis.LEFT by default to share the scale of the Plot, ValueAxis.RIGHT for a scale of their own on the right.

Returns:

  • Self

    A new Plot; this one is left unchanged.

Raises:

  • InvalidTypeError

    When an argument is not of the type its annotation names.

  • RefusedSettingError

    When the Plot does not draw lines, vertical bars or points.

  • IncompatibleChartsError

    When the x values are not of the kind of the ones of the Plot: numbers, dates, texts or times of day; or when one measures numbers and the other times of day on the same axis.

  • DuplicateLabelError

    When a label appears twice in the x values of one chart placed on labels.

  • InvalidChartDataError

    When a Table has no y column, or an Array has a column setting.

  • InvalidColorCountError

    When color is given for an Array of several columns.

Examples:

import numdaplot as ndp

days = ndp.Array.from_list([1, 2, 3, 4, 5, 6])
trend = ndp.Array.from_list([10.0, 12.0, 14.0, 16.0, 18.0, 20.0])
measures = ndp.Array.from_list([10.5, 11.2, 14.8, 15.1, 18.9, 19.4])
readings = ndp.Table.from_arrays({"day": days, "trend": trend, "measure": measures})
plot = ndp.Plot.line(readings, ndp.LineChart(x="day", y=["trend"]))
points = ndp.ScatterChart(x="day", y="measure")
both = plot.add_scatter(readings, points)
both.show()

Plot drawn by the example

Output

show() Source

Show the Plot: as an image in a Jupyter notebook, in a matplotlib window anywhere else.

In a script, the window stays open until it is closed. When no window can be opened, because Python has no tkinter or runs on a server, nothing is shown and a DisplayWarning suggests saving the Plot instead.

Added in version 0.1.0

Examples:

import numdaplot as ndp

prices = ndp.Array.from_list([12.0, 15.5, 14.0, 17.0])
plot = ndp.Plot.bar(prices)
plot.show()

Plot drawn by the example

save(path, options=None, on_conflict=Conflict.ERROR) Source

Save the Plot as an image, in the format named by the extension of the path.

.png gives an image made of pixels, .svg and .pdf images made of lines and texts that stay sharp at any zoom. The image has the size of the style, 640 by 480 pixels for a PNG image by default.

Added in version 0.1.0

Parameters:

  • path (FilePath)

    The path of the image, a FilePath such as "chart.png" or Path("images/chart.svg"), ending with .png, .svg or .pdf.

  • options (ImageOptions | None, default: None)

    The resolution of a PNG image, 100 dots per inch when omitted. SVG and PDF images take none.

  • on_conflict (Conflict, default: Conflict.ERROR)

    ERROR by default, refusing to overwrite an existing file, or REPLACE to overwrite it.

Raises:

Examples:

import tempfile
from pathlib import Path
import numdaplot as ndp

path = Path(tempfile.mkdtemp()) / "prices.svg"
prices = ndp.Array.from_list([12.0, 15.5, 14.0])
plot = ndp.Plot.line(prices)
plot.save(path)
path.read_text().startswith("<?xml")
# True

to_matplotlib() Source

Return a new matplotlib figure of the Plot, to change it with matplotlib.

Changing the figure never changes the Plot. The figure is not managed by matplotlib.pyplot, so a notebook does not display it on its own.

Added in version 0.1.0

Returns:

  • matplotlib.figure.Figure

    The figure, drawn on a single matplotlib Axes.

Examples:

import numdaplot as ndp

prices = ndp.Array.from_list([12.0, 15.5, 14.0])
style = ndp.PlotStyle(title="Prices")
figure = ndp.Plot.line(prices, style=style).to_matplotlib()
figure.get_suptitle()
# 'Prices'
figure.axes[0].lines[0].get_ydata()
# array([12. , 15.5, 14. ])