Skip to content

Instantly share code, notes, and snippets.

@koepferl
Last active November 16, 2021 11:55
Show Gist options
  • Save koepferl/6bf7d8bc8f094a394c46a7f3cd86eef5 to your computer and use it in GitHub Desktop.
Save koepferl/6bf7d8bc8f094a394c46a7f3cd86eef5 to your computer and use it in GitHub Desktop.
Animated Images
name: example-environment
dependencies:
- python=3.7
- numpy
- matplotlib
- ipywidgets
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.image as mpimg\n",
"\n",
"import numpy as np\n",
"\n",
"# interactive plots\n",
"from ipywidgets import interactive\n",
"import ipywidgets as widgets\n",
"\n",
"import matplotlib as mpl\n",
"mpl.rcParams['figure.dpi']= 300\n",
"\n",
"evo = ['024', '025', '026', '027', '028', '029', '030', '031', '032', \n",
" '042', '052', '062', '072', '082', '092', '102', '112', '122', '132', '142', '152', '162', '172']\n",
"evo_time = [3.576, 3.725, 3.874, 4.023, 4.172, 4.321, 4.47, 4.619, \n",
" 4.768, 4.917, 5.066, 5.215, 5.364, 5.513, 5.662, 5.811, 5.96, 6.109, 6.258, 6.407, 6.556, 6.705, 6.854]\n",
"\n",
"\n",
"def update_fig7(time = widgets.FloatSlider(min=3.576, max=6.854, step=0.149, value=3.576, description='time [Myrs]:'),\n",
" ori = widgets.RadioButtons(options=['O1', 'O2', 'O3'],\n",
" # value='pineapple', # Defaults to 'pineapple'\n",
" # layout={'width': 'max-content'}, # If the items' names are long\n",
" description='Orientation:',\n",
" disabled=False, orientation='horizontal'), \n",
" dist = widgets.RadioButtons(options=['D1', 'D2'],\n",
" description='Distance:',\n",
" disabled=False)):\n",
" \n",
" file = 'analysis_v1/analysis_2021/fit_all/I' + evo[evo_time.index(time)] + '_CM2_' + ori + '_' + dist + '_B1_R2_all_fit.png'\n",
" \n",
" fig = plt.figure()\n",
" ax = fig.add_subplot(111)\n",
" img = mpimg.imread(file)\n",
" imgplot = plt.imshow(img)\n",
" fig.patch.set_visible(False)\n",
" ax.axis('off')\n",
" plt.show()\n",
" \n",
"\n",
"def update_fig5(time = widgets.FloatSlider(min=3.576, max=6.854, step=0.149, value=3.576, description='time [Myrs]:'),\n",
" dist = widgets.RadioButtons(options=['D1', 'D2'],\n",
" description='Distance:',\n",
" disabled=False)):\n",
" \n",
" file = 'analysis_v1/analysis_2021/map_analysis/PDF_I' + evo[evo_time.index(time)] + '_CM2_O3_' + dist + '_B1_R2_obs_analysis.png'\n",
" \n",
" fig = plt.figure()\n",
" ax = fig.add_subplot(111)\n",
" img = mpimg.imread(file)\n",
" imgplot = plt.imshow(img)\n",
" fig.patch.set_visible(False)\n",
" ax.axis('off')\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6f2961c96d43466fb7872a701eb29b01",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=3.576, description='time [Myrs]:', max=6.854, min=3.576, step=0.149), …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"############\n",
"# Figure 7 #\n",
"############\n",
"from ipywidgets import interactive\n",
"interactive_plot = interactive(update_fig7)\n",
"interactive_plot"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "377937e7175047ca99420b28c4ce3795",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=3.576, description='time [Myrs]:', max=6.854, min=3.576, step=0.149), …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"############\n",
"# Figure 5 #\n",
"############\n",
"from ipywidgets import interactive\n",
"interactive_plot = interactive(update_fig5)\n",
"interactive_plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment