[Python] Order points in seaborn

Discussão em 'Python' iniciado por Stack, Junho 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to make a stripplot / point plot / scatter plot, where the points in each category are sorted, based on the y value (see example in this forum post). I would like the points in each gene category sorted (as in the linked example with the two categories: placebo and full).

    How can this be done in seaborn / pandas?

    A simple example input would be:

    pd.DataFrame({
    "Gene": ["Gene1", "Gene1", "Gene1", "Gene1", "Gene1", "Gene1",
    "Gene2", "Gene2", "Gene2", "Gene2", "Gene2", "Gene2"],
    "Value": [80, 1205, 5, 150, 50, 80,
    12, 5235, 235, 1245, 126, 10]})


    And more elaborate:

    pd.DataFrame({
    "Gene": ["Gene1", "Gene1", "Gene1", "Gene1", "Gene1", "Gene1",
    "Gene2", "Gene2", "Gene2", "Gene2", "Gene2", "Gene2"],
    "Value": [80, 1205, 5, 150, 50, 80,
    12, 5235, 235, 1245, 126, 10]}),
    "State": ["active", "inactive", "active", "inactive", "active", "active",
    "active", "active", "active", "inactive", "inactive", "inactive"]})


    So the genes are the y-ticks, the values are the points and the activity is the hue.

    Example of a stripplot, to illustrate the desired result: [​IMG]

    Continue reading...

Compartilhe esta Página