| [ Web Proxy ] |
| Viewing: https://bqplot.github.io/bqplot | [Back] [Original] |
bqplot is a python based 2-D visualization system for Jupyter, based on the constructs of Grammar of Graphics. In bqplot every component of the plot is an interactive widget. This allows the user to seamlessly integrate bqplot with other Jupyter widgets to create rich visualizations by using just python code!
figure and mark objects are implemented as traitlets which make the plots respond to data updates. After rendering the charts the attributes of the figures and marks can be updated in notebook cells down (or in callbacks) and changes are automatically reflected in the chart!Object Model can be extended to build reusable compound plotting widgets and widget librariesbqplot with other Jupyter widget libraries and voila dashboarding toolWhile bqplot provides support for static plotting for most of the chart types, it really shines in interactive plotting where data attributes are updated in an event-driven fashion (using ipywidgets, click handlers etc.)
Two APIs are provided in bqplot:
pyplot is the best way to get started on bqplot. Creating a plot involves 3 steps:
DOMWidgetimport bqplot.pyplot as plt
import numpy as np
fig = plt.figure(title="Sine")
# create data vectors
x = np.linspace(-10, 10, 200)
y = np.sin(x)
# create line mark
line = plt.plot(x, y)
# renders the figure in the output cell (with toolbar for panzoom, save etc.)
plt.show()
[plot]
Object Model is a verbose (but fully customizable) API for creating plots. Creating a plot involves the following steps:
scales for data attributes (x, y, color etc.)marks using the above scalesaxes objects using the above scalesfigure object and pass the marks and axes as parametersimport numpy as np
import bqplot as bq
x = np.linspace(-10, 10, 200)
y = np.sin(x)
# create scales
xs = bq.LinearScale()
ys = bq.LinearScale()
# create mark objects
line = bq.Lines(x=x, y=y, scales={"x": xs, "y": ys})
# create axes objects
xax = bq.Axis(scale=xs, grid_lines="solid", label="X")
yax = bq.Axis(scale=ys, orientation="vertical", grid_lines="solid")
# create the figure object (renders in the output cell)
bq.Figure(marks=[line], axes=[xax, yax], title="Sine")
[plot]
To enhance the plots (colors, grid lines, axes labels, ticks, legends etc.) you need to pass in additional parameters to the plotting widget constructors/methods. Let's look at an example:
fig = plt.figure(title="Sine", legend_location="top-left")
x = np.linspace(-10, 10, 100)
# multi line chart
y = [np.sin(x), np.cos(x)]
# customize axes
axes_options = {
"x": {"label": "X"},
"y": {"label": "Y", "tick_format": ".2f"}
}
curves = plt.plot(
x,
y,
colors=["red", "green"],
display_legend=True,
axes_options=axes_options,
labels=["Sine", "Cosine"]
)
fig
[plot]
Have a look at Usage section for more details on how to configure and customize various plots
| Web Proxy Viewer | New URL | Original Page |