Last active
September 22, 2020 20:51
-
-
Save liaskast/ab29bfc9fe534f784afbdc46b956a4bf to your computer and use it in GitHub Desktop.
Test of bqplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: bqplot-test | |
channels: | |
- conda-forge | |
- defaults | |
dependencies: | |
- python | |
- ipywidgets >=5.2.2 | |
- traitlets >=4.3.0 | |
- traittypes >=0.0.6 | |
- numpy >=1.10.4 | |
- pandas | |
- bqplot | |
- pytest # test dependency | |
- pytest-cov # test dependency | |
- jupyterlab # test dependency | |
- selenium # test dependency | |
- mock # test dependency | |
- nose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import bqplot.pyplot as plt" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"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": null, | |
"metadata": {}, | |
"outputs": [], | |
"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": {}, | |
"outputs": [], | |
"source": [ | |
"fig.save_png()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Line Chart with dates as x data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"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": null, | |
"metadata": {}, | |
"outputs": [], | |
"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": null, | |
"metadata": {}, | |
"outputs": [], | |
"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": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"fig = plt.figure()\n", | |
"plt.hist(y_data)\n", | |
"fig" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Bar Chart" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"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.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment