Skip to content

Nishant1201/interactive-zoom-matplotlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Interactive Zoomed Axes for Matplotlib 🔍

Python Matplotlib License

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.

✨ Features

  • 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.

🚀 Installation

  1. 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
  2. Install requirements: You simply need matplotlib and numpy. If you are running this in a Jupyter environment, you also need ipympl.

    pip install matplotlib numpy ipympl

📖 Usage

Running the Demo

Simply run the main script to see the interactive demo:

python ZoomedAxes.py

Using in Your Own Code

Copy 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()

For Jupyter Notebooks / Google Colab

Ensure you enable the widget backend at the start of your notebook:

%matplotlib widget
import matplotlib.pyplot as plt
# ... import DraggableZoomV2 ... 

Inspiration

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.

Author

Nishant Soni Expert in CFD, HPC, and Scientific Computing.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A robust, fully interactive implementation of "Zoomed Inset Axes" for Python and Matplotlib.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages