Skip to content

Commit 557c5ff

Browse files
committed
finishing up
1 parent 712a989 commit 557c5ff

File tree

9 files changed

+35
-20
lines changed

9 files changed

+35
-20
lines changed
34.7 KB
Loading

paper/imgs/sin-composed.png

1.23 MB
Loading

paper/imgs/sinusoid_1-dark.png

22.5 KB
Loading

paper/imgs/sinusoid_2-dark.png

20.3 KB
Loading

paper/imgs/sinusoid_3-dark.png

23 KB
Loading

paper/imgs/sinusoid_4-dark.png

23.8 KB
Loading

paper/imgs/threshold-dark.png

267 KB
Loading

paper/paper.bib

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
@article{Pearson:2017,
2-
url = {http://adsabs.harvard.edu/abs/2017arXiv170304627P},
3-
Archiveprefix = {arXiv},
4-
Author = {{Pearson}, S. and {Price-Whelan}, A.~M. and {Johnston}, K.~V.},
5-
Eprint = {1703.04627},
6-
Journal = {ArXiv e-prints},
7-
Keywords = {Astrophysics - Astrophysics of Galaxies},
8-
Month = mar,
9-
Title = {{Gaps in Globular Cluster Streams: Pal 5 and the Galactic Bar}},
10-
Year = 2017
1+
@Article{Hunter:2007,
2+
Author = {Hunter, J. D.},
3+
Title = {Matplotlib: A 2D graphics environment},
4+
Journal = {Computing in Science \& Engineering},
5+
Volume = {9},
6+
Number = {3},
7+
Pages = {90--95},
8+
abstract = {Matplotlib is a 2D graphics package used for Python for
9+
application development, interactive scripting, and publication-quality
10+
image generation across user interfaces and operating systems.},
11+
publisher = {IEEE COMPUTER SOC},
12+
doi = {10.1109/MCSE.2007.55},
13+
year = 2007
1114
}
15+
16+
@unpublished{interactive_Jupyter_widgets,
17+
author = {Jupyter widgets community},
18+
title = {ipywidgets, a GitHub repository},
19+
year = {2015},
20+
note = {Retrieved from https://github.com/jupyter-widgets/ipywidgets}
21+
}

paper/paper.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
title: "mpl-interactions: A Python package for Interactive Matplotlib Figures"
33
tags:
44
- Python
5-
- some-other-tags-maybe
5+
- Matplotlib
6+
- Ipywidgets
7+
- Interactive
8+
- Visualization
69
authors:
710
- name: Ian Hunt-Isaak
811
orcid: 0000-0002-7591-083X
@@ -15,15 +18,15 @@ affiliations:
1518
index: 1
1619
- name: Department of Molecular and Cellular Biology, Harvard University, Cambridge, MA, USA
1720
index: 2
18-
date: 14 February 2023
21+
date: 31 May 2023
1922
bibliography: paper.bib
2023
---
2124

2225
# Summary
2326

2427
<!-- A summary describing the high-level functionality and purpose of the software for a diverse, non-specialist audience. -->
2528

26-
Data exploration, model building and pedagogy all benefit from the ability to interactively update elements in Matplotlib figures. `mpl-interactions` enables this by making it easy for users to create matplotlib figures in which the displayed data can be dynamically controlled through widgets. These widgets can be automatically generated by passing arguments such as arrays or shorthands (such as a tuple of numbers to generate a slider) to modified pyplot functions. After creation of these widgets, `mpl-interactions` updates plot elements without further user intervention. For ease of use, it adds these features while otherwise staying close to the `matplotlib.pyplot` interface. `mpl-interactions` is built such that parameters controlled by the generated widgets are easy to re-use for multiple plot elements, while not interfering with static elements. This design allows for building any figure that `matplotlib` can produce, while adding interactivity to specific parts as desired.
29+
Data exploration, model building and pedagogy all benefit from the ability to interactively update elements in Matplotlib [@Hunter:2007] figures. `mpl-interactions` enables this by making it easy for users to create matplotlib figures in which the displayed data can be dynamically controlled through widgets. These widgets can be automatically generated by passing arguments such as arrays or shorthands (such as a tuple of numbers to generate a slider) to modified pyplot functions. After creation of these widgets, `mpl-interactions` updates plot elements without further user intervention. For ease of use, it adds these features while otherwise staying close to the `matplotlib.pyplot` interface. `mpl-interactions` is built such that parameters controlled by the generated widgets are easy to re-use for multiple plot elements, while not interfering with static elements. This design allows for building any figure that `matplotlib` can produce, while adding interactivity to specific parts as desired.
2730

2831
Complete Tutorials, Examples, and API documentation are available on https://mpl-interactions.readthedocs.io/en/stable/.
2932

@@ -33,7 +36,7 @@ Complete Tutorials, Examples, and API documentation are available on https://mpl
3336

3437
The ability to interact dynamically with plots through widgets such as sliders can be a powerful tool in the scientific process and in pedagogy. For instance, varying a parameter of a mathematical model plotted on top of data helps to understand the relationship between the model and the data. Similarly, exploratory data analysis can be enhanced by interactively modifying aspects of the plot such as which points are displayed, or the threshold level of a displayed image.
3538

36-
Matplotlib provides mechanisms for updating elements (artists) in figures. However, the APIs for these artists are not consistent and some are under- or undocumented. Furthermore, the creation and positioning of the native Matplotlib widgets is nontrivial. While the `ipywidgets` library makes widget creation and positioning easier, it is difficult to integrate with matplotlib in a performant manner. The easiest way to do so is to use the `ipywidgets`' `interact()` function, which automatically generates sliders and other widgets to control arguments to arbitrary python functions. However, this can result in completely regenerating the figure which can be slow. Alternatively, the user needs to remember the specifics of how to update each individual artist. The final issue is that `ipywidgets` is a general framework, and thus constrained in its choices of how to interpret shorthands for widget generation -- as such, the choices it makes are not always optimal for scientific plotting.
39+
Matplotlib provides mechanisms for updating elements (artists) in figures. However, the APIs for these artists are not consistent and some are under- or undocumented. Furthermore, the creation and positioning of the native Matplotlib widgets is nontrivial. While the `ipywidgets` [@interactive_Jupyter_widgets] library makes widget creation and positioning easier, it is difficult to integrate with matplotlib in a performant manner. The easiest way to do so is to use the `ipywidgets`' `interact()` function, which automatically generates sliders and other widgets to control arguments to arbitrary python functions. However, this can result in completely regenerating the figure which can be slow. Alternatively, the user needs to remember the specifics of how to update each individual artist. The final issue is that `ipywidgets` is a general framework, and thus constrained in its choices of how to interpret shorthands for widget generation -- as such, the choices it makes are not always optimal for scientific plotting.
3740

3841
While `matplotlib` and `ipywidgets` provide the tools for controlling plots with widgets, the overhead of implementing such control can overwhelm its utility. `mpl-interactions` fills this gap by making it easy for users to generate widgets that dynamically control plots.
3942

@@ -57,7 +60,7 @@ ctrls = iplt.plot(x, sinusoid, A=(1, 10), f = (.5, 2))
5760
plt.show()
5861
```
5962

60-
![Multiple states of the figure resulting from moving the sliders after running above example in jupyter lab.\label{fig:sinusoid}](imgs/sinusoid-full.png)
63+
![Multiple states of the figure resulting from moving the sliders after running above example in jupyter lab.\label{fig:sinusoid}](imgs/sin-composed.png)
6164

6265
A second important feature of `mpl-interactions` is that interactive plot components are not isolated from each other. That is, the control widgets generated from one plotting call can be re-used to control other components. In addition to showing the re-use of control widgets this example demonstrates how matplotlib styling arguments (such as `vmin`) can be controlled through widgets.
6366

@@ -84,9 +87,9 @@ axs[1].set_title("Histogram of Pixel Intensities")
8487
axs[1].set_xlabel('Pixel Intensity')
8588
```
8689

87-
![An imshow where the thresholds of the colorbar are controlled by the `vmin_vmax` range slider. While the slider is created by the `imshow` call, its interactive parameters can be reused to control the position of the veritcal lines on the histogram.](imgs/threshold.png)
90+
![An imshow where the thresholds of the colorbar are controlled by the `vmin_vmax` range slider. While the slider is created by the `imshow` call, its interactive parameters can be reused to control the position of the veritcal lines on the histogram.](imgs/threshold-dark.png)
8891

89-
Finally, `mpl-interactions` allows the reuse of Python functions performing mathematical operations in multiple parts of user code, rather than writing requiring users to write a plotting specific version. For example below the `logistic_growth` function is used for both curve fitting and an interactive display in order to better understand the role of the model parameters.
92+
Finally, `mpl-interactions` allows the reuse of Python functions performing mathematical operations in multiple parts of user code, rather than requiring users to write a plotting specific version. For example, below the `logistic_growth` function is used for both curve fitting and an interactive display in order to better understand the role of the model parameters.
9093

9194
```python
9295
%matplotlib ipympl
@@ -132,14 +135,16 @@ axs[1].plot(t_data, logistic_growth(t_data, *popt), "--", label="fit")
132135
plt.legend()
133136
```
134137

135-
![Generated figure and sliders after running above example in jupyter lab.\label{fig:logistic}](imgs/logistic_growth.png){ width=75% }
138+
![Generated figure and sliders after running above example in jupyter lab.\label{fig:logistic}](imgs/logistic_growth-dark.png){ width=75% }
136139

137140
This framework makes it easy generate complex interactive visualizations. It also enables `mpl-interactions` to manage generating GIFs. Any parameter controlled through `mpl-interactions` can be used to automatically generate a gif of the plot changing as a function of that parameter ([Animation Documentation](https://mpl-interactions.readthedocs.io/en/stable/examples/animations.html)). Thus `mpl-interactions` can assist across the data visualization process, from initial exploration to the creation of a final animated plot as a GIF.
138141

139142
# Acknowledgements
140143

141-
We thank Dr. K. Dalton for stimulating discussions, and [CONTRIBUTIONS]. This work was supported by a National Defense Science and Engineering Graduate Fellowship (IHI, add award number), the George W. Merck Fund of the New York Community Trust (award 338034, to DRH), and funds from Harvard University.
144+
WThis work was supported by a National Defense Science and Engineering Graduate Fellowship (FA9550-19-F-0008, to IHI), the George W. Merck Fund of the New York Community Trust (award 338034, to DRH), and funds from Harvard University.
142145

143-
In addition, many users have contributed features and bug fixes. Of particular note are Remco de Boer, John Russell, and Samantha Hamilton who made contributions to documentation and code, code, and documentation respectively. A full list of coding contributors can be found here: https://github.com/mpl-extensions/mpl-interactions/graphs/contributors
146+
We thank Dr. K. Dalton from stimulating discussion, and Easun Arunchalam for feedback on drafts of this paper. In addition, many users have contributed features and bug fixes. Of particular note are Remco de Boer, John Russell, and Samantha Hamilton who made contributions to documentation and code, code, and documentation respectively. A full list of coding contributors can be found here: https://github.com/mpl-extensions/mpl-interactions/graphs/contributors
144147

145148
Finally, many users have contributed in ways other than coding. For example by raising issues either with the package or documentation. These users are recognized here: https://github.com/mpl-extensions/mpl-interactions#contributors-
149+
150+
# References

0 commit comments

Comments
 (0)