如何将交互式 Matplotlib 图形保存为 excel 或图形?我只是想与非技术用户分享。但是,我可以使用 Plotly 并共享链接来做到这一点,但由于数据隐私问题,他们不喜欢这种方法。有什么方法可以做到吗?
我有如下交互式图像。有些是堆叠在一起的。所以需要缩放这就是为什么我需要以互动的方式保存图像。然后非技术用户可以放大并检查结果。
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()