Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

matplotlib - Visualizations are getting duplicated when using ipywidgets in Python jupyter notebooks

This is the code that I am using to output a drop down and a visualization. However with the drop down the visualization duplicates when I select a value.

def common_filtering(year): output.clear_output() plot_output.clear_output()

common_filter = Top_Team(year)

with output:
    display(common_filter)
    
with plot_output:
    plt.ioff
    test = common_filter.player_name.tolist()
    x = [10,35,30,30,35,65,65,65,100,95,95] 
    y = [40,10,30,50,70,20,40,60,40,60,20]
    plt.style.use('ggplot')
    pitch = Pitch(pitch_type='statsbomb', orientation='vertical',
                  pitch_color='#22312b', line_color='#c7d5cc', figsize=(16, 20),
                  constrained_layout=True, tight_layout=False,axis = True,label = True)
    fig, ax = pitch.draw() 
    sc = pitch.scatter(x, y,
                          color ='red',edgecolors = 'black',
                            s=40000, ax=ax)

    for i,j,k in zip(x,y,test):
        
          pitch.annotate(k, (i,j),c='white', va='top', ha='center', size=16, weight='bold', ax=ax)

    fig.set_facecolor("#22312b")
    display(fig)

def dropdown_year_eventhandler(change): common_filtering(change.new)

dropdown_year.observe( dropdown_year_eventhandler, names='value')

display(dropdown_year) -- This is where the drop down is seen and underneath the duplicated visualizations

This is where essentially the output should be coming from and it is. display(plot_output) display(output)

question from:https://stackoverflow.com/questions/65545776/visualizations-are-getting-duplicated-when-using-ipywidgets-in-python-jupyter-no

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...