My code reads data from .xlsx file and it plots the Bubble diagram by using plotly. Bubble Diagram The task is easy when I do know how many traces need to be plot. However, I was thrown into bewilderment when the number of traces is unfixed since the number of rows is variable.
1991 1992 1993 1994 1995 1996 1997
US 10 14 16 18 20 42 64
JAPAN 100 30 70 85 30 42 64
CN 50 22 30 65 70 66 60
Here is my uncompleted code:
# Version 2 could read data from .xlsx file.
import plotly as py
import plotly.graph_objs as go
import openpyxl
wb = openpyxl.load_workbook(('grape output.xlsx'))
sheet = wb['Sheet1']
row_max = sheet.max_row
col_max = sheet.max_column
l=[]
for row_n in range(row_max-1):
l.append([])
for col_n in range(col_max-1):
l[row_n].append(sheet.cell(row=row_n+2, column=col_n+2).value)
trace0 = go.Scatter(
x=[1991, 1992, 1993, 1994, 1995, 1996, 1997],
y=['US', 'US', 'US', 'US', 'US', 'US', 'US'],
mode='markers+text',
marker=dict(
color='rgb(150,204,90)',
size= l[0],
showscale = False,
),
text=list(map(str, l[0])),
textposition='middle center',
)
trace1 = go.Scatter(
x=[1991, 1992, 1993, 1994, 1995, 1996, 1997],
y=['JAPAN', 'JAPAN', 'JAPAN', 'JAPAN', 'JAPAN', 'JAPAN', 'JAPAN'],
mode='markers+text',
marker=dict(
color='rgb(255, 130, 71)',
size=l[1],
showscale=False,
),
text=list(map(str,l[1])),
textposition='middle center',
)
trace2 = go.Scatter(
x=[1991, 1992, 1993, 1994, 1995, 1996, 1997],
y=['CN', 'CN', 'CN', 'CN', 'CN', 'CN', 'CN'],
mode='markers+text',
marker=dict(
color='rgb(255, 193, 37)',
size=l[2],
showscale=False,
),
text=list(map(str,l[2])),
textposition='middle center',
)
layout = go.Layout(plot_bgcolor='rgb(10, 10, 10)',
paper_bgcolor='rgb(20, 55, 100)',
font={
'size': 15,
'family': 'sans-serif',
'color': 'rgb(255, 255, 255)'
},
width=1000,
height=500,
xaxis=dict(title='Output of grapes per year in US, JAPAN and CN', ),
showlegend=False,
margin=dict(l=100, r=100, t=100, b=100),
hovermode = False,
)
data = [trace0, trace1, trace2]
fig = go.Figure(data=data, layout=layout)
py.offline.init_notebook_mode()
py.offline.plot(fig, filename='basic-scatter.html')
Could you please teach me how to draw them? Thx




plotly.express?codenot as pictures.print(df)