I want to combine a parallel coordinates plot, a table, and a choropleth into a single go.FigureWidget(). I want to do this so that I can link the data between the plots (i.e., clicking on the parallel coordinates plot updates the table and the choropleth). For the go.Parcats() and the go.Table() there is a domain argument, however, for go.Choropleth() a domain argument doesn’t exist. I need to set the domain argument to prevent the 3 graphs from overlapping. Is there a hidden domain argument for go.Choropleth() or a workaround?
I want to combine a parallel coordinates plot, a table, and a choropleth into a single go.FigureWidget(). I want to do this so that I can link the data between the plots (i.e., clicking on the parallel coordinates plot updates the table and the choropleth). For the go.Parcats() and the go.Table() there is a domain argument, however, for go.Choropleth() a domain argument doesn’t exist. I need to set the domain argument to prevent myLoyola Portal the 3 graphs from overlapping. Is there a hidden domain argument for go.Choropleth() or a workaround?
In Plotly, go.Choropleth does not have a built-in domain argument like go.Parcats and go.Table. However, you can still achieve the layout you desire by using a combination of plotly.subplots.make_subplots() and adjusting the specs argument to define the layout of your plots. This allows you to control the positioning of each subplot and prevent overlapping.
Here’s a basic outline of how you can set this up:
Use Subplots: Create a subplot layout where you specify the number of rows and columns.
Add Your Plots: Use fig.add_trace() to add each of your plots to the appropriate subplot location.
Linking Interactivity: Use Dash or a similar framework to add interactivity, allowing selections in the parallel coordinates plot to update the table and choropleth accordingly.
Here’s an example:
import plotly.graph_objects as go
from plotly.subplots import make_subplots
Sample data
data = {
‘labels’: [‘A’, ‘B’, ‘C’],
‘values’: [10, 20, 30],
}
Create subplots
fig = make_subplots(
rows=2, cols=2,
specs=[[{“type”: “parcats”}, {“type”: “table”}],
[{“type”: “choropleth”}, None]],
vertical_spacing=0.1
)
Add Parallel Coordinates plot
fig.add_trace(
go.Parcats(
dimensions=[
dict(label=‘Dimension 1’, values=[1, 2, 3]),
dict(label=‘Dimension 2’, values=[10, 20, 30]),
],
),
row=1, col=1
)
Add Table
fig.add_trace(
go.Table(
header=dict(values=[‘A’, ‘B’, ‘C’]),
cells=dict(values=[[1, 2, 3], [4, 5, 6]])
),
row=1, col=2
)
Add Choropleth
fig.add_trace(
go.Choropleth(
z=data[‘values’],
locations=data[‘labels’],
locationmode=‘country names’,
colorbar=dict(title=“Values”),
),
row=2, col=1
)
Update layout to set overall layout options
fig.update_layout(height=800, width=800, title_text=“Combined Visualizations”)
fig.show()
Linking the Data
To implement the interactivity between the plots, consider using Dash:
Dash Callbacks: Use callbacks to link the plots. When a selection is made in the parallel coordinates plot, update the data in the table and choropleth based on that selection.
from dash import Dash, dcc, html, Input, Output
app = Dash(name)
app.layout = html.Div([
dcc.Graph(id=‘main-graph’, figure=fig)
])
@app.callback(
Output(‘main-graph’, ‘figure’),
Input(‘some-input’, ‘value’) # Replace with actual inputs from your parallel coordinates
)
def update_graph(selected_value):
# Logic to update figure based on selected_value
return updated_fig # Return the updated figure
if name == ‘main’:
app.run_server(debug=True)
I need to use Shiny for my project. I was hoping I could just use my go.FigureWidget() linking functioning, but it doesn’t seem to work. Any hints? It appears that points.point_inds
no longer exists.
def update_color(trace, points, state):
# Update parcats colors
new_color = 1
new_color[points.point_inds] = 0.5
fig.data[0].line.color = new_color
# update the table
tmp_df = mod_df.iloc[points.point_inds,]
fig.data[1].cells.values = list(tmp_df.loc[:, ['col1', 'col2', 'col3]].transpose().itertuples(index=False, name=None))
# Register callback on parcats click
fig.data[0].on_click(update_color)