So far I tried to plot a scatter plot as below:
import plotly.express as px
fig = px.scatter(df,
y="Antecedent",
x="Consequent",
size="Absolute_Frequency",
color="Absolute_Frequency")
fig.update_traces(
hovertemplate="<br>".join([
"Antecedent: %{y}",
"Consequent: %{x}"
]),
name=""
)
fig.update_layout(
template="plotly_white",
# Figure title styling
title= dict(
text="Precedence Matrix",
x=0.5,
y=0.95,
font=dict(
family="Rockwell",
size=20,
color='#000000'
)
),
xaxis_title="Consequent",
yaxis_title="Antecedent",
font=dict(
family="Rockwell",
size=16),
# Fig height
height=600,
width=1200,
# Turn off legend
showlegend=False,
hoverlabel=dict(
bgcolor="white",
font_size=16,
font_family="Rockwell"
)
)
fig.show()
How to add the text annotations and create rectangles in plotly as per the bupar Precedence Matrix
?
EDIT: after you remove the argument size="Absolute_Frequency"
, you can change the marker size and set the font size to get something closer to the image you showed originally.
fig = px.scatter(df,
y="Antecedent",
x="Consequent",
# size="Absolute_Frequency",
color="Absolute_Frequency",
text="Absolute_Frequency"
)
fig.update_traces(
hovertemplate="<br>".join([
"Antecedent: %{y}",
"Consequent: %{x}"
]),
name=""
)
fig.update_layout(
template="plotly_white",
# Figure title styling
title= dict(
text="Precedence Matrix",
x=0.5,
y=0.95,
font=dict(
family="Rockwell",
size=20,
color='#000000'
)
),
xaxis_title="Consequent",
yaxis_title="Antecedent",
font=dict(
family="Rockwell",
size=16),
# Fig height
height=600,
width=1200,
# Turn off legend
showlegend=False,
hoverlabel=dict(
bgcolor="white",
font_size=16,
font_family="Rockwell"
)
)
fig.update_traces(
marker={'symbol': 'square', 'size': 50},
textfont_color='white',
textfont_size=14,
textposition='middle center'
)
fig.show()