How to Saving an interactive Matplotlib figure

1.7k Views Asked by At

How can I save an interactive Matplotlib figure to excel or just as figure? I just want to share those with non-technical users. However, I can do that using Plotly and share the link but because of data privacy issues, they don't prefer that method. Is there any method I can do that?

I have interactive images like below. Some are stacked together. So need to zoom that's why I need to save images in an interactive mood. Then non-technical users can zoom in and check the results.

import pandas as pd

import matplotlib
import mplcursors

data = [['Alex',10000,15000,6705],['Bob',12000,11050,7050],['Clarke',10300,10450,9050],['Alan',10100,15500,6205],['Sam',10300,15050,6785]]
df = pd.DataFrame(data,columns=['Name','Year2019','Year2020','Year2021'])
dfLen = len(df)

x =df['Year2020']
if dfLen > 0:
    %matplotlib notebook
    %matplotlib notebook  
    import matplotlib.pyplot as plt
    fig , ax = plt.subplots(figsize=(8,6))
    a = df['Year2019']/100
    # Create a scatter plot (Use s - make the size of each vendors usage)
    plt.scatter('Year2019', 'Year2020',s= x , c='Year2019', data=df)
    plt.title("2019 Vs 2020 sold items",fontsize=12)
    plt.xlabel('2019', fontsize=10)
    plt.ylabel('2020',fontsize=10)
    list1 = list(df['Name'])
    i = 0;              
    for row in df.itertuples():
        h = list1[i]
        i=i+1
        h = str(h)
        c = row.Year2019
        d = row.Year2020
        ax.text(c,d,s = h, size = 8)
    crs = mplcursors.cursor(ax,hover=True)
    crs.connect("add", lambda sel: sel.annotation.set_text(
        'Point x - {} ,\n'
               'y- {}'.format(sel.target[0], sel.target[1])))
    plt.show()
0

There are 0 best solutions below