[Python] Removing a value from X-axis of violin plot

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently plotting the diameter of 5 trees as measured by a large group of people.

    I have created a violin plot using the below code:

    fig=sns.violinplot(data=simple_tree_metrics,
    y='DCH_cm', x= 'tree_id',
    palette="tab10").get_figure()


    The resulting violin plot is below:

    violin plot

    While the plot is successfully plotting trees 1-5, a non-existent tree 0 has also been plotted.

    I have tried to drop tree 0 using

    simple_tree_metrics.drop(simple_tree_metrics.loc[simple_tree_metrics['tree_id']=='0'].index, inplace=True)

    but when locating tree 0 in the df, there are no results. I have also checked the data in excel and there is no data for a tree 0 so I am not sure where this is coming from.

    Continue reading...

Compartilhe esta Página