Skip to content

PlotStyle(title=None, x_label=None, y_label=None, right_label=None, x_tick_rotation=None, y_tick_rotation=None, legend=LegendPosition.BEST, grid_lines=GridLines.SHOWN, size=Size(), renaming=None) Source

Look of a whole Plot: title, axis labels, rotation of the values, legend, grid lines and size.

The look of the series, such as their colors, belongs to the chart drawing them.

Added in version 0.1.0

Changed in version 0.2.0

The title is centered above the whole Plot, and goes on several lines when it is too wide. The axis of several series is labeled Value by default, their names staying in the legend and the title.

Parameters:

  • title (str | None, default: None)

    The title, centered above the whole Plot and broken into lines when it is too wide: when omitted, the y label by the x label such as sales by month, and for a map of missing values Map of missing values. Several columns labeled Value are named in the title one after the other, the first 3 and the number of the others beyond 3, such as price, cost by month. An empty text draws no title.

  • x_label (str | None, default: None)

    The label of the axis of the x values: when omitted, the name of the x column, else Row, or Column for a box or a heatmap without group. For a histogram, whose values are on this axis, the name of its single column, else Value. An empty text draws no label.

  • y_label (str | None, default: None)

    The label of the axis of the y values: when omitted, the name of the single y column, else Value for several columns, which the legend names, and for an Array. An empty text draws no label.

  • right_label (str | None, default: None)

    The label of the axis on the right, drawn when a chart is added with ValueAxis.RIGHT: when omitted, written as y_label for the first chart on the right. An empty text draws no label. It has no effect while no chart is on the right.

  • x_tick_rotation (float | None, default: None)

    The angle of the labels of the x values, in degrees from -90 to 90. When omitted, 45 degrees for texts, dates, datetimes and numbers without enough room, and no rotation for other numbers and for the texts on the left of horizontal bars. Labels without enough room at this angle are left out, one out of as many as needed from the first one, with a ReadabilityWarning when they may be texts.

  • y_tick_rotation (float | None, default: None)

    The angle of the labels of the y values, in degrees from -90 to 90, no rotation when omitted. The values of the axis on the right keep no rotation. Labels without enough room are left out as for x_tick_rotation.

  • legend (LegendPosition, default: LegendPosition.BEST)

    Where the legend is placed, LegendPosition.BEST by default, past the axes for a map of missing values. It is only drawn for several series, so never on a pie or a heatmap. It names each series after its column, or after the name renaming gives it.

  • grid_lines (GridLines, default: GridLines.SHOWN)

    Whether light grid lines are drawn behind the values, GridLines.SHOWN by default. A pie and a heatmap have none.

  • size (Size, default: Size())

    The width and the height, 6.4 by 4.8 inches by default. A Plot placed in a Figure takes the size of its cells instead.

  • renaming (Renaming | None, default: None)

    The names under which some columns are shown, every column under its own name when omitted. Each NameChange applies to the legend, the labels of boxes, heatmaps and missing value charts, the legends of color_by and size_by, and the default title and axis labels, on every chart of the Plot. The columns of an Array are named "0", "1"... The values themselves, such as the parts of a pie, are never renamed. A title or a label given here keeps its text.

Raises:

Examples:

import numdaplot as ndp

days = ndp.Array.from_list([1, 2, 3, 4])
prices = ndp.Array.from_list([12.0, 15.5, 14.0, 17.0])
costs = ndp.Array.from_list([8.0, 9.5, 9.0, 10.0])
sales = ndp.Table.from_arrays({"day": days, "price": prices, "cost": costs})
chart = ndp.LineChart(x="day", y=["price", "cost"])
style = ndp.PlotStyle(title="Sales", x_label="Day", y_label="Euros", legend=ndp.LegendPosition.OUTSIDE_RIGHT)
plot = ndp.Plot.line(sales, chart, style)
plot.show()

Plot drawn by the example

The labels of the x values can take another angle.

cities = ndp.Array.from_list(["Paris", "Lyon", "Marseille"])
totals = ndp.Array.from_list([120.0, 80.0, 95.0])
city_sales = ndp.Table.from_arrays({"city": cities, "total": totals})
city_chart = ndp.BarChart(x="city", y=["total"])
city_plot = ndp.Plot.bar(city_sales, city_chart, ndp.PlotStyle(x_tick_rotation=90))
city_plot.show()

Plot drawn by the example

The columns can be shown under other names, without renaming them in the Table.

shown_names = ndp.Renaming(changes=[ndp.NameChange(old_name="total", new_name="Total sales")])
named_plot = ndp.Plot.bar(city_sales, city_chart, ndp.PlotStyle(renaming=shown_names))
named_plot.show()

Plot drawn by the example