A robust, fully interactive implementation of "Zoomed Inset Axes" for Python and Matplotlib.
This project recreates the functionality of MathWorks' "Zoomed Axes" toolbox but adds dynamic interactivity suited for modern scientific workflows. It allows users to visualize dense signals with high-fidelity inset plots that can be panned, moved, and zoomed interactively.
- Interactive Panning: Drag the zoom indicator box on the main plot to scan through different regions of your data.
- Draggable Insets: Move the floating inset plots anywhere on the figure to avoid obscuring important data.
- Scroll-to-Zoom: Hover over the indicator box and use the mouse scroll wheel to dynamically increase or decrease the zoom level.
- Live Updates: The inset plots update in real-time with high performance (memory-leak free).
- Dark Mode Support: Pre-configured with a sleek dark aesthetic for professional presentations.
- Jupyter/Colab Compatible: Works seamlessly in Jupyter Notebooks and Google Colab using
ipympl.
-
Clone the repository:
git clone [https://github.com/Nishant1201/interactive-zoom-matplotlib.git](https://github.com/Nishant1201/interactive-zoom-matplotlib.git) cd interactive-zoom-matplotlib -
Install requirements: You simply need
matplotlibandnumpy. If you are running this in a Jupyter environment, you also needipympl.pip install matplotlib numpy ipympl
Simply run the main script to see the interactive demo:
python ZoomedAxes.pyCopy the DraggableZoomV2 class into your project.
import matplotlib.pyplot as plt
from zoom_tools import DraggableZoomV2 # Assuming you saved the class in zoom_tools.py
fig, ax = plt.subplots()
ax.plot(x, y)
# 1. Create an inset axes using standard Matplotlib syntax
axins = ax.inset_axes([0.5, 0.5, 0.4, 0.4])
axins.plot(x, y)
# 2. Make it interactive!
zoom = DraggableZoomV2(ax, axins)
plt.show()Ensure you enable the widget backend at the start of your notebook:
%matplotlib widget
import matplotlib.pyplot as plt
# ... import DraggableZoomV2 ... This project was inspired by the MathWorks Blog post on "Zoomed Axes". The goal was to demonstrate how Python's scientific stack can replicate and extend proprietary tool functionality with open-source flexibility.
Nishant Soni Expert in CFD, HPC, and Scientific Computing.
This project is licensed under the MIT License - see the LICENSE file for details.