Skip to content

Instantly share code, notes, and snippets.

@Pabla007
Created June 6, 2019 13:04
Show Gist options
  • Save Pabla007/8d357661e9268302ea20ca258db70b52 to your computer and use it in GitHub Desktop.
Save Pabla007/8d357661e9268302ea20ca258db70b52 to your computer and use it in GitHub Desktop.
work bqplot in nbveiwer.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import bqplot.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"size = 100\n",
"scale = 100.\n",
"np.random.seed(0)\n",
"x_data = np.arange(size)\n",
"y_data = np.cumsum(np.random.randn(size) * scale)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Line Chart"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2f90cd08cf1045adbde3e5ad28ac4dbc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = plt.figure(title='First Example')\n",
"plt.plot(y_data)\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This image can be saved by calling the `save_png` function of the `Figure` object:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"fig.save_png()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Line Chart with dates as x data"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')\n",
"size = len(dates)\n",
"prices = scale + 5 * np.cumsum(np.random.randn(size))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6398587bfa36440ca9efebbb50795125",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(label='Date', scale=DateScale(), tick_format='%m/%d'), Axis(label='Price', orientation='vert…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = plt.figure(title='Changing Styles', background_style={'fill': 'lightgreen'},\n",
" title_style={'font-size': '20px','fill': 'DarkOrange'})\n",
"axes_options = {'x': {'label': 'Date', 'tick_format': '%m/%d'},\n",
" 'y': {'label': 'Price', 'tick_format': '0.0f'}}\n",
"plt.plot(dates, prices, 'b', axes_options=axes_options) # third argument is the marker string\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Scatter Chart"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f299a1fdc9494ef3a71edb148372632c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = plt.figure()\n",
"axes_options = {'x': {'label': 'Date', 'tick_format': '%m/%d'},\n",
" 'y': {'label': 'Price', 'tick_format': '0.0f'}}\n",
"\n",
"plt.scatter(x_data, y_data, colors=['red'], stroke='black')\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Histogram"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c55302fb2ad74a80a5b879b3b57a1978",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale())], fig_margin={'top':…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = plt.figure()\n",
"plt.hist(y_data)\n",
"fig"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bar Chart"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2394e2e4861b471e8d69d341df16219e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(label='X', scale=OrdinalScale()), Axis(label='Y', orientation='vertical', scale=LinearScale(…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import string\n",
"\n",
"fig = plt.figure(padding_x=0)\n",
"axes_options = {'x': {'label': 'X'}, 'y': {'label': 'Y'}}\n",
"plt.bar(x=list(string.ascii_uppercase), y=np.abs(y_data[:20]), axes_options=axes_options)\n",
"fig"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment