It is a graph used to improve various visualizations, such as distributions of parliamentarians, assembly members or congressmen. I have not found this graph natively in plotly, but I am adding a simple example of how to generate it from a simple dataset. Parameters are required to generate this chart such as the number of rows, the radius of the initial row, the total angle and the size of the mark. I hope it is useful to you!.
Some functions necessary to generate the radii and angles:
import math
def Sort_Tuple(tup):
return sorted(tup, key=lambda x: x[1])
def parlamentary_Coord(df,angle_total=180,rows=4, ratio=6,initial='NAME'):
arco_total = 0
angles = []
for i in range(rows):
arco_total += math.pi * int(ratio+i)
for i in range(rows):
arco_radio = math.pi * int(ratio+i)
angles.append(angle_total/round(arco_radio/(arco_total/len(df)),0))
coord = []
for a in range(len(angles)):
current_angle = angles[a]/2
for i in range(int(round(angle_total/angles[a],0))):
coord.append((ratio+a, current_angle))
current_angle += angles[a]
coord = Sort_Tuple(coord)
df["radio"] = list(zip(*coord))[0]
df["tetha"] = list(zip(*coord))[1]
df["INITIAL"] = df[initial].apply(lambda x: x[0])
return df
For this chart we use px.scatter_polar:
import plotly.express as px
#config for parlamentary plot
graph_style = "plotly_dark" #template plotly
height = 500 # height plot
angle_total = 240 # all cover plot, recomended 90Β° - 300Β°
size_marker = 32 #config by size angle_total in design
#df your dataframe
df = parlamentary_Coord(df,angle_total,5,6)
angle_start = (180 - angle_total)/2
angle_end = 180 + (angle_total - 180)/2
# recomended use 'PARTIDO', 'COLOR' in your dataframe
d_ict = df[["PARTIDO", "COLOR"]]
d_ict = d_ict.drop_duplicates()
dct = dict(d_ict.values)
fig = px.scatter_polar(
df,
r="radio",
theta="tetha",
color="PARTIDO",
color_discrete_map=dct,
text="INITIAL",
start_angle=angle_start,
custom_data=["NAME"],
range_theta=[angle_start, angle_end],
direction="counterclockwise",
)
fig.update_layout(
xaxis=dict(showgrid=False),
yaxis=dict(showgrid=False),
margin=dict(b=20, r=5, l=5, t=10),
height=height,
polar=dict(
radialaxis=dict(
showticklabels=False, ticks="", linecolor="rgba(255, 255, 255, 0)"
),
angularaxis=dict(showticklabels=False, ticks="", linecolor="rgba(0,0,0,0)"),
),
polar_radialaxis_gridcolor="rgba(0,0,0,0)",
polar_angularaxis_gridcolor="rgba(0,0,0,0)",
)
fig.update_traces(textposition="middle center")
fig.update_traces(
hovertemplate="<b>%{customdata[0]}</b><extra></extra>",
textfont_size=12,
)
fig.update_layout(
template=graph_style,
autosize=True,
showlegend=False,
uniformtext_minsize=8,
uniformtext_mode="hide",
font=dict(family="Arial, monospace", size=12),
)
fig.update_traces(marker=dict(opacity=0.7, size=size_marker))
fig.show()
Example: angle_total = 240 ; size_marker = 30
Example: angle_total = 180 ; size_marker = 32
Example: angle_total = 90 ; size_marker = 20