简体   繁体   中英

How to add up more data in an existing plotly graph?

I have successfully plotted the below data using plotly from an Excel file.

在此处输入图像描述

Here is my code:

file_loc1 = "AgeGroupData_time_to_treatment.xlsx"

df_centroid_CoordNew = pd.read_excel(file_loc1, index_col=None, na_values=['NA'], usecols="C:D,AB")
df_centroid_CoordNew.head()

df_centroid_Coord['Ambulance_Treatment_Time'] = df_centroid_Coord ['Base_TT']

fig = px.scatter(df_centroid_Coord, x="x", y="y", 
                 title="Southern Region Centroids", 
                 color='Ambulance_Treatment_Time', 
                 hover_name="KnNamn",
                 hover_data= ['Ambulance_Treatment_Time', "TotPop"],
                 log_x=True, size_max=60, 
                 color_continuous_scale='Reds', range_color=(0.5,2), width=1250, height=1000)

fig.update_traces(marker={'size': 8, 'symbol': 1})
#fig.update_traces(marker={'symbol': 1})
fig.update_layout(paper_bgcolor="LightSteelBlue")

fig.show()

The shapes of the plotted data points are square.

Here is output of my code:

在此处输入图像描述

Now, I want to plot more data points in circle or any shapes on the same plotly graph by reading an excel file. Please have a look at the data below.

在此处输入图像描述

How I can add up the new data to an existing graph in plotly?

If the data is the same but the column names are different, aligning to either column name is fine for the data for the chart. Add a graph with a graph object by reusing the graph data created with plotly.express. First I added a chart that was already completed, then a chart with latitude and longitude. Station names and locations are drawn using scatterplot markers and text mode.

import plotly.express as px
import plotly.graph_objects as go

df_centroid_Coord['Ambulance_Treatment_Time'] = df_centroid_Coord ['Base_TT']

sca = px.scatter(df_centroid_Coord, x="x", y="y", 
                 title="Southern Region Centroids", 
                 color='Ambulance_Treatment_Time', 
                 #hover_name="KnNamn",
                 #hover_data= ['Ambulance_Treatment_Time', "TotPop"],
                 log_x=True,
                 size_max=60, 
                 color_continuous_scale='Reds',
                 range_color=(0.5,2),
                 )

sca.update_traces(marker={'size': 8, 'symbol': 1})

fig = go.Figure()
fig.add_trace(go.Scatter(sca.data[0]))
fig.add_trace(go.Scatter(x=df_station['x'],
                         y=df_station['y'],
                         mode='markers+text',
                         text=df_station['Ambulance station name'],
                         textposition='top center',
                         marker=dict(
                             size=5,
                             symbol=2,
                             color='blue'
                         )
                        )
             )
              
#fig.update_traces(marker={'symbol': 1})
fig.update_layout(width=625, height=500, paper_bgcolor="LightSteelBlue")

fig.show()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM