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:
objectBar-chart plot panel.
Not an anywidget. Holds state in
_statedict; 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:
- 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 aliasx_centers.
- 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
Trueany non-positive values are clamped to1e-10for 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:
- add_hline_widget(y, color='#00e5ff')[source]#
Add a draggable horizontal line at value-axis position y.
- Parameters:
- Return type:
- 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.
- add_point_widget(x, y, color='#00e5ff', show_crosshair=True, _push=True)[source]#
Add a freely-draggable control point to this panel.
- on_click(fn)[source]#
Decorator: fires when the user clicks a bar.
The
Eventhasbar_index,value,x_center, andx_label.
- 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, andlast_widget_id.- Return type: