import numpy as np
import bqplot.pyplot as plt
size = 100
scale = 100.
np.random.seed(0)
x_data = np.arange(size)
y_data = np.cumsum(np.random.randn(size) * scale)
fig = plt.figure(title='First Example')
plt.plot(y_data)
fig
This image can be saved by calling the save_png
function of the Figure
object:
fig.save_png()
dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')
size = len(dates)
prices = scale + 5 * np.cumsum(np.random.randn(size))
fig = plt.figure(title='Changing Styles', background_style={'fill': 'lightgreen'},
title_style={'font-size': '20px','fill': 'DarkOrange'})
axes_options = {'x': {'label': 'Date', 'tick_format': '%m/%d'},
'y': {'label': 'Price', 'tick_format': '0.0f'}}
plt.plot(dates, prices, 'b', axes_options=axes_options) # third argument is the marker string
fig
fig = plt.figure()
axes_options = {'x': {'label': 'Date', 'tick_format': '%m/%d'},
'y': {'label': 'Price', 'tick_format': '0.0f'}}
plt.scatter(x_data, y_data, colors=['red'], stroke='black')
fig
fig = plt.figure()
plt.hist(y_data)
fig
import string
fig = plt.figure(padding_x=0)
axes_options = {'x': {'label': 'X'}, 'y': {'label': 'Y'}}
plt.bar(x=list(string.ascii_uppercase), y=np.abs(y_data[:20]), axes_options=axes_options)
fig