Search code examples
pythonmatplotlibplot

How to plot a vectorized graph in Jupyter notebook?


I have a dataframe or np.array and want to plot a vectorized (i.e. infinitely zoomable a.k.a. non rasterized image) graph.

I want it to be as simple as matplotlib (by that I mean you can plot multiple graphs on the same figure, subplots, etc).

I have already tried Plotly but found it too complicated, correct me if I'm wrong though


Solution

  • You can use interactive plots if start your notebook using the %matplotlib widget magic method at the top of the first cell. Make sure you have ipympl installed in your environment. Here is an example with an illustration:

    %matplotlib widget
    from matplotlib import pyplot as plt
    import numpy as np
    
    data = np.random.randn(100, 2)
    
    fig, ax = plt.subplots()
    ax.plot(*data.T, 'o')
    

    And it will generate an interactive figure in which you can pan and zoom etc. using mouse gestures or the UI shown to the left of the chart below: enter image description here