Reference 〉 Class
ChartPlot

BarChart(horizontalboolFalse, logscaleboolFalse)

A plot type, compatible with Charts, that displays live-updating bar charts.

This class should not be instantiated directly; use Charts.addPlot(type='bar') instead. The optional init options can be passed to that function as kwargs.

Features

  • Can be displayed either horizontally or vertically
  • Automatically scales to accommodate new data
  • Agent reporters registered with the std or percentiles arguments will display as error bars on the bar chart.

Initialization Parameters

  • horizontal bool, optional

    Whether to draw the bar chart horizontally or vertically.

    Default value: False

  • logscale bool, optional

    Whether to draw the plot on a logarithmic scale on the axis of variation (horizontal or vertical). Note that all series values must be positive for a logarithmic scale to work.

    Default value: False

Methods

Click a method name for more detailed documentation.

  • active( val, updateGUI )

    Turns on or off the selected state of a plot in the control panel.

  • addBar( reporter, label, color, … )

    Registers a data reporter as a bar on the current plot. To display error bars, use the std or percentiles arguments when creating the agent reporter.

  • draw( t, forceUpdate )

    Updates the axes object for display on the visualizer. This function is called after ChartPlot.update() when the visualizer receives new data, and when scrubbing the time bar. The update() method, therefore, should be used to store model data by time, which can then be used by draw().

    Charts will refresh the entire canvas after updating each of the individual plots, so there is no need to refresh the canvas manually here unless it is desired to redraw the graph out of sync (e.g. if the subclass provides for interactivity and the plot should update while the model is paused).

    Subclasses should call super().draw(t, forceUpdate) at the end of the function.

  • MPLEvent( event )

    An event handling method that can be overridden in subclasses to catch pick (pick_event), keypress (key_press_event), and mouse click (button_press_event) events that occur inside a particular plot. This is distinct from functions passed to MPLVisualization.addKeypress(), as those will run for keys pressed any time the visualization window is in focus, regardless of the mouse position.

    For example, pressing 'l' with the mouse over a AgentsPlot will rotate the layout. The key pressed can be accessed with event.key.

    This function should not be called by user code, but it may be defined in subclasses of ChartPlot. event.canvas.draw_idle() should be called at the end if the plot needs to be refreshed following the event. See the Matplotlib events documentation for more on interacting with the event object.

  • update( data, t )

    Receives current model data and stores it for future scrubbing.

    Note that this function is called when the visualizer receives new data from the model. Because ChartPlot.draw() is called both after ChartPlot.update() and when the time bar is scrubbed, drawing code should be put in ChartPlot.draw() and not here, unless there is code to be run only in the event of new data that should not be run when scrubbing (e.g. calculating new plot bounds).

    If the visualizer needs model properties besides the current data, the model object can be accessed with self.viz.model.

    This function should not typically be called from user code, though it can be for out-of-sync plot updates when interacting with a plot. See the agentClick hook for an example.

  • launch( axes )

    Initial code to set up ChartPlot.axes when Charts launches the visualization window. Subclasses should call super().launch() at the beginning of the method. This function should not be called from user code.

Object Properties

  • type str

    A short identifying string, to be used in the type argument of Charts.addPlot().

  • name str

    A short name, used to refer back to the plot afterward.

  • label str

    The title of the chart, displayed above it in the visualizer.

  • axes matplotlib.AxesSubplot

    The AxesSubplot object to be drawn to the plot area. The object is created on Charts.launch() and passed to ChartPlot.launch(), where it must be stored subsequently.

  • projection str

    The Matplotlib coordinate projection to use. None defaults to 'rectilinear', but other projections available by default are 'polar', '3d', 'aitoff', 'hammer', 'lambert', and 'mollweide'. Custom Matplotlib projection objects can also be passed to this argument.

    Initial value: None

  • viz Charts

    The parent Charts visualizer object.

  • selected bool

    Whether the plot is currently queued for display. Do not modify this property directly; use ChartPlot.active() to ensure consistency with the GUI state.

  • bars list[Series]

    The data series that have been registered as bars in the current plot.

  • horizontal bool

    Whether to draw the bar chart horizontally or vertically.

    Initial value: False

  • logscale bool

    Whether to draw the plot on a logarithmic scale on the axis of variation (horizontal or vertical). Note that all series values must be positive for a logarithmic scale to work.

    Initial value: False

Notes and Examples

  1. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.

History