So I am studying the global terrorism dataset that can be found on kaggle: https://www.kaggle.com/ash316/terrorism-around-the-world and I would like to make a line charts of the top 10 terrorist groups based on their activity (“Group” column) with the “Year” column on the x-axis.
How can I do just that ? I tried:
fig = px.line(df, x=df.Year, color=df.Group.value_counts().nlargest(10).index, width=800, height=800)
fig.update_layout(legend_orientation="h")
fig.show()
But that gives me the error:
ValueError: All arguments should have the same length. The length of argument \color` is 10, whereas the length of previous arguments ['Year'] is 170350`
It works fine when I do it in this specific way but since there are just way too many terrorist groups, this results in a very ugly visualization and I must make the legend orientation horizontal… and I end up with a super long legend…
fig = px.line(df, x=df.Year, color=df.Group, width=800, height=800)
fig.update_layout(legend_orientation="h")
fig.show()