In [ ]:
import numpy as np
import bqplot.pyplot as plt
from bqplot import LinearScale, Axis, Figure, Scatter
In [ ]:
np.random.seed(0)
size = 100
x = range(size)
y1 = np.cumsum(np.random.randn(size) * 100.0)
y2 = np.cumsum(np.random.randn(size))
In [ ]:
fig = plt.figure()
line = plt.plot(np.arange(10), np.arange(10), colors=['hotpink', 'orange'])
fig
In [ ]:
# set the grid lines of axes to dashed
xax, yax = plt.axes()['x'], plt.axes()['y']
xax.grid_lines = 'dashed'
yax.grid_lines = 'dashed'
In [ ]:
# Change the side of the axis
yax.side = 'right'
xax.side = 'top'
In [ ]:
# change the orientation of axes
yax.orientation = 'horizontal'
xax.orientation = 'vertical'
In [ ]:
# Change the format of the ticks on the axis
yax.tick_format = '0.2f'
xax.tick_format = '0.0f'
In [ ]:
# Change the color of the axis
with xax.hold_sync():
xax.color = 'orangered'
xax.label_color = 'orangered'
In [ ]:
# change the grid colors
xax.grid_color = 'red'
In [ ]:
fig = plt.figure()
axes_options = {'x': {'label': 'X'}, 'y': {'label': 'Y'}}
line = plt.plot(x, y1, colors=['orangered'], axes_options=axes_options)
fig
In [ ]:
xax, yax = plt.axes()['x'], plt.axes()['y']
# moving the label along the axis
xax.label_location = 'end'
yax.label_location = 'start'
In [ ]:
# moving the label perpendicular to the axis
yax.label_offset = '6ex'
xax.label_offset = '-1em'
In [ ]:
fig = plt.figure()
line = plt.plot(x[:20], y1[:20], 'm')
fig
In [ ]:
xax, yax = plt.axes()['x'], plt.axes()['y']
In [ ]:
# Setting the number of ticks
xax.num_ticks = 8
In [ ]:
# Setting the tick values
xax.tick_values = np.arange(1, 21)
In [ ]:
# Setting the style for the text of the ticks
xax.tick_style = {'stroke': 'orangered', 'font-size': 14}
In [ ]:
# using object model for this example
sc_x = LinearScale()
sc_y = LinearScale(reverse=True)
sc_y2 = LinearScale()
sc1 = Scatter(x=x[:10], y=y1[:10],
scales={'x': sc_x, 'y': sc_y},
default_size=100)
sc2 = Scatter(x=x[:10], y=y2[:10],
colors=['dodgerblue'],
marker='cross', scales={'x': sc_x, 'y': sc_y2})
In [ ]:
## Setting offset for axis in terms of figure scales
xax = Axis(label='Test X', scale=sc_x,
grid_lines='solid', offset=dict(value=0.2), label_location="start")
yax = Axis(label='Test Y', scale=sc_y,
orientation='vertical', tick_format='0.2f',
grid_lines='solid', label_location="end")
yax2 = Axis(label='Test Y2', scale=sc_y2, orientation='vertical', side='right',
tick_format='0.2f')
Figure(axes=[xax, yax, yax2], marks=[sc1, sc2], legend_location='top-right',
padding_x=0.025)
In [ ]:
# restoring to default position
xax.offset = {}
In [ ]:
yax.offset = dict(value=3.0, scale=sc_x)
In [ ]:
# add a fig margin to allow place for color bar
fig = plt.figure(fig_margin=dict(top=80, left=80, right=80, bottom=80))
scatter = plt.scatter(x, y1, color=y2, stroke='black')
fig
In [ ]:
xax, yax, cax = plt.axes()['x'], plt.axes()['y'], plt.axes()['color']
cax.side = 'top'
In [ ]:
with cax.hold_sync():
cax.orientation = 'vertical'
cax.side = 'right'
In [ ]:
yax.side = 'right'
cax.side = 'left'