mpl-interactions: A Python Package for Interactive Matplotlib Figures

Publication information:

Ian Hunt-Isaak, John Russell, and Doeke Hekstra. 2024. “Mpl-Interactions: A Python Package for Interactive Matplotlib Figures”. Journal of Open Source Software

Abstract

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.