def plot_file ( file , title , limit = 100 ): df = pd . read_csv ( file ) #drop unused columns df = df . drop ( columns = [ 'Province/State' , 'Lat' , 'Long' ]) #sum province/state from the same country #aggregate per country and transpose the table per_country = df . groupby ( 'Country/Region' ) . sum () . transpose () #convert string date to date obj per_country . index = per_country . index . map ( lambda x : datetime . strptime ( x , '%m/ %d /%y' )) per_country . sort_index ( inplace = True ) keep_countries = per_country . columns [ per_country . max () >= limit ] per_country = per_country [ keep_countries ] #plot fig = go . Figure () for country in per_country . columns : fig . add_trace ( go . Scatter ( x = per_country . index , y = per_country [ country ], mode = 'lines+markers' , hovertemplate = f "<b> {country} </b><br><br>" + "% {yaxis.title.text} : % {y:,.0f} <br>" + "% {xaxis.title.text} : % {x} <br>" + "<extra></extra>" , name = country )) updatemenus = list ([ dict ( active = 1 , buttons = list ([ dict ( label = 'Log Scale' , method = 'update' , args = [{ 'visible' : [ True ] * len ( per_country . columns )}, { 'title' : f ' {title} (Log scale)' , 'yaxis' : { 'type' : 'log' , 'title' : 'Number of Cases' }}]), dict ( label = 'Linear Scale' , method = 'update' , args = [{ 'visible' : [ True ] * len ( per_country . columns )}, { 'title' : f ' {title} (Linear scale)' , 'yaxis' : { 'type' : 'linear' , 'title' : 'Number of Cases' }}]) ]), ) ]) #customize layout fig . update_layout ( title = f ' {title} (Linear scale)' , xaxis_title = 'Date' , yaxis_title = 'Number of Cases' , autosize = True , height = 600 , updatemenus = updatemenus , annotations = [ dict ( xref = 'paper' , yref = 'paper' , x = 0.5 , y = 1.1 , showarrow = False , text = f 'Only countries with more than {limit} {title} <br>at any given point in time' )]) fig . show ()