Code Monkey home page Code Monkey logo

mpl-interactions's Introduction

mpl_interactions

All Contributors

Documentation StatusBinder (Warning: The interactions will be laggy when on binder)

Welcome!

mpl_interactions' library provides helpful ways to interact with Matplotlib plots. A summary of key components can be found below. Fuller narrative, further examples, and more information can be found on ReadtheDocs.

There are three submodules:

pyplot

Control Matplotlib plots using sliders and other widgets to adjust the parameters of the functions you are plotting. If working in a notebook then ipywidgets will be used to make the sliders, otherwise Matplotlib widgets will be used.

This is a different approach to controlling plots with sliders than ipywidgets.interact as when using interact you are responsible for:

  1. Defining the function to plot f(x,...) => y
  2. Handling the plotting logic (plt.plot, fig.cla, ax.set_ylim, etc)

In contrast, with mpl-interactions you only need to provide f(x, ...) => y and the plotting and updating boilerplate are handled for you.

x = np.linspace(0,6,100)
beta = np.linspace(0,5*np.pi)
def f(x, beta):
    return np.sin(x*4+beta)
interactive_plot(f, x=x, beta=beta)

These functions are designed to be used with ipympl, the backend that is designed for use in Jupyter Notebooks. So for optimal performance, make sure you set the backend with %matplotlib ipympl. That said, these functions will also work with any interactive backend (e.g. %matplotlib qt5).

generic

Provides ways to interact with Matplotlib that will work outside of a Jupyter Notebook; this should work equally well with any backend.

  1. A very niche (but very cool) way to compare 2D heatmaps
  2. Scroll to zoom
  3. Middle click to pan

utils

This module includes utility functions to make things just that little bit easier.

  1. ioff as a context manager
from mpl_interactions.utils import ioff
with ioff:
    # interactive mode will be off
    fig = plt.figure()
    # other stuff
# interactive mode will be on
  1. figure that accepts a scalar for figsize (this will scale the default dimensions)
from mpl_interactions.utils import figure
fig = figure(3)
# the default figsize is [6.4, 4.8], this figure will have figsize = [6.4*3, 4.8*3]
  1. nearest_idx -- avoid ever having to write np.argmin(np.abs(arr - value)) again

Installation

pip install mpl_interactions

# if using jupyterlab
conda install -c conda-forge nodejs=13
jupyter labextension install @jupyter-widgets/jupyterlab-manager

If you use JupyterLab, make sure you follow the full instructions in the ipympl readme in particular installing jupyterlab-manager.

Contributing / feature requests / roadmap

I use the GitHub issues to keep track of ideas I have, so looking through those should serve as a roadmap of sorts. For the most part I add to the library when I create a function that is useful for the science I am doing. If you create something that seems useful a PR would be most welcome so we can share it easily with more people. I'm also open to feature requests if you have an idea.

Documentation

The fuller narrative documentation can be found on ReadTheDocs. You may also find it helpful to check out the examples directory.

Examples with GIFs!

Tragically, neither GitHub nor the sphinx documentation render the actual moving plots so instead, here are gifs of the functions. The code for these can be found in the notebooks in the examples directory.

interactive_plot

Easily make a line plot interactive:

heatmap_slicer

Compare vertical and horizontal slices across multiple heatmaps:

scrolling zoom + middle click pan

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Ian Hunt-Isaak

๐Ÿ’ป

Sam

๐Ÿ“–

Jenny Coulter

๐Ÿ““

Sabina Haque

๐Ÿ“– ๐Ÿ““ ๐Ÿ’ป

John Russell

๐Ÿ’ป ๐Ÿ““ ๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

mpl-interactions's People

Contributors

allcontributors[bot] avatar ianhi avatar jrussell25 avatar samanthahamilton avatar sjhaque14 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.