我想使用 Matplotlib 小部件制作下拉菜单

问题描述

我的图表无法改变。当我尝试在图中使用 y_sel 和 x_sel 时,它会引发错误。 有时它会显示错误“国家/地区”,有时会显示一个类似值的输入过多。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as widgets
import seaborn as sns
from IPython.display import display
%matplotlib inline

ydata = online_act_major.loc[ :,['socionet','info_good_serv','banking','selling','news','learn_act'] ]
    xdata = online_act_major.index.values
    # gca stands for 'get current axis'
    dropdown = widgets.Dropdown(
        options=ydata,value='selling',description='Indicators:',)

def Dropdown_Menu(value='selling'):
    ax = plt.gca()
    fig = plt.gcf()
    fig.set_size_inches(15,5)
    #pairs = [(a,b) for a,b in zip(xdata,ydata) if a == value] # use `==` to get only one value
    #y_sel,x_sel = zip(*pairs)
    # select values
    y_sel = ydata
    x_sel = xdata
    #plot graph from two diffrent dataFrame corresponding to years 2019 and 2020
    online_act_major.plot(kind='line',x='Countries',y = 'selling',label = 'Sales 2019',ax=ax)
    online_act_20_major.plot(kind='line',y='selling',color='red',label = 'Sales 2020',ax=ax)
#plt.show()
widgets.interact(Dropdown_Menu,value=dropdown)

I want graph can be changed according to chosen indicator

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)