anyplotlib.PlotBar#

class anyplotlib.PlotBar(x, height=None, width=0.8, bottom=0.0, *, align='center', color='#4fc3f7', colors=None, orient='v', log_scale=False, group_labels=None, group_colors=None, show_values=False, units='', y_units='', x_labels=None, x_centers=None, bar_width=None, baseline=None, values=None)[source]#

Bases: object

Bar-chart plot panel.

Not an anywidget. Holds state in _state dict; every mutation calls _push() which writes to the parent Figure’s panel trait.

Supports grouped bars (pass a 2-D height array with shape (N, G)), log-scale value axis, draggable overlay widgets, and hover/click callbacks.

Created by Axes.bar().

Parameters:
to_state_dict()[source]#
Return type:

dict

set_data(height, x=None, x_labels=None, *, x_centers=None)[source]#

Replace bar heights; recalculates the value-axis range automatically.

Parameters:
  • height (array-like, shape (N,) or (N, G)) – New bar heights. For grouped charts the group count G must match the original.

  • x (array-like of numeric, optional) – New bar positions (replaces the stored x_centers). Also accepts the legacy keyword alias x_centers.

  • x_labels (list of str, optional) – New category labels.

Return type:

None

set_color(color)[source]#

Set a single colour for all bars.

Parameters:

color (str)

Return type:

None

set_colors(colors)[source]#

Set per-bar colours (list of CSS colour strings, length N).

Return type:

None

set_show_values(show)[source]#

Show or hide in-bar value annotations.

Parameters:

show (bool)

Return type:

None

set_log_scale(log_scale)[source]#

Enable or disable a logarithmic value axis.

When log_scale is True any non-positive values are clamped to 1e-10 for display; the data-range bounds are recalculated in log-space automatically.

Parameters:

log_scale (bool)

Return type:

None

add_vline_widget(x, color='#00e5ff')[source]#

Add a draggable vertical line at data position x.

Parameters:
Return type:

VLineWidget

add_hline_widget(y, color='#00e5ff')[source]#

Add a draggable horizontal line at value-axis position y.

Parameters:
Return type:

HLineWidget

add_range_widget(x0, x1, color='#00e5ff', style='band', y=0.0, _push=True)[source]#

Add a draggable range overlay. See Plot1D.add_range_widget() for full docs.

Parameters:
Return type:

RangeWidget

add_point_widget(x, y, color='#00e5ff', show_crosshair=True, _push=True)[source]#

Add a freely-draggable control point to this panel.

Parameters:
Return type:

PointWidget

get_widget(wid)[source]#

Return the Widget object by ID string or Widget instance.

Return type:

Widget

remove_widget(wid)[source]#

Remove a widget by ID string or Widget instance.

Return type:

None

list_widgets()[source]#
Return type:

list

clear_widgets()[source]#
Return type:

None

on_click(fn)[source]#

Decorator: fires when the user clicks a bar.

The Event has bar_index, value, x_center, and x_label.

Parameters:

fn (Callable)

Return type:

Callable

on_changed(fn)[source]#

Decorator: fires on every drag frame (widget drag or hover).

Parameters:

fn (Callable)

Return type:

Callable

on_release(fn)[source]#

Decorator: fires once when a widget drag settles.

Parameters:

fn (Callable)

Return type:

Callable

on_key(key_or_fn=None)[source]#

Register a key-press handler for this panel.

Two call forms are supported:

@plot.on_key('q')          # fires only when 'q' is pressed
def handler(event): ...

@plot.on_key               # fires for every registered key
def handler(event): ...

The event carries: key, mouse_x, mouse_y, and last_widget_id.

Return type:

Callable

disconnect(cid)[source]#
Parameters:

cid (int)

Return type:

None