Skip to content

Objects so.Plot.facet cannot handle multiple dataframes #3878

@Auerilas

Description

@Auerilas

Hi,
I'm trying to build a plot with facets, and I have two dataframes: one of the data points and one of the fitted predictions. The objects interface struggles with faceting when there are two separate dataframes.

Data:

print(ecoplate_richness.head())
Site Soil days_dead OnOff OD-H2O
0 Airport granite 697 Off 19
1 Airport granite 697 On 18
2 Albasini granite 1210 Off 22
3 Albasini granite 1210 On 23
4 Big Bull basalt 767 Off 23

print(pred_df.head())
index OnOff Soil days_dead OD lower upper
0 0 On granite 42.000000 17.802223 16.539523 19.161324
1 1 On granite 53.797980 18.081813 16.914838 19.329298
2 2 On granite 65.595960 18.308901 17.216830 19.470243
3 3 On granite 77.393939 18.500509 17.468669 19.593296
4 4 On granite 89.191919 18.666474 17.683850 19.703699

Here are the graphs. The first one produces the correctly faceted dots, but doesn't split the prediction lines by color.

#%% plot
g = (
    so.Plot(data=ecoplate_richness)
    .add(so.Dot(), x='days_dead', y='OD-H2O', color='OnOff', data=ecoplate_richness.reset_index())
    .add(so.Line(), x='days_dead', y='OD', color='OnOff', data=pred_df)
    .facet('Soil')
    .limit(x=(10, 5000))
    .scale(x=so.Continuous(trans='log').tick(at=[1, 10,  100, 1000]).label(like="{x:g}"),
          #  y=so.Continuous(trans='log')
    )
    .label(y='Ecoplate Richness',
           x='Days Post-Mortem')
    .theme(theme)

)
g.save('richness1.png', bbox_inches='tight', dpi=300)
g.show()

[

Image

](url)

versus the second one, which correctly plots the prediction lines but doesn't facet the dots:

g = (
    so.Plot(data=pred_df)
    .add(so.Dot(), x='days_dead', y='OD-H2O', color='OnOff', data=ecoplate_richness.reset_index())
    .add(so.Line(), x='days_dead', y='OD', color='OnOff', data=pred_df)
    .facet('Soil')
    .limit(x=(10, 5000))
    .scale(x=so.Continuous(trans='log').tick(at=[1, 10,  100, 1000]).label(like="{x:g}"),
          #  y=so.Continuous(trans='log')
    )
    .label(y='Ecoplate Richness',
           x='Days Post-Mortem')
    .theme(theme)

)
g.save('richness2.png', bbox_inches='tight', dpi=300)
g.show()
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions