Skip to content

geom_contour: error if data is not sorted properly #1357

@ASmirnov-HORIS

Description

@ASmirnov-HORIS

geom_contour() fails with an unclear error when the input data is not ordered in a specific way. This happens even when the data forms a valid and complete grid.

Example:

df = pd.DataFrame({
    'x': [0, 0, 1, 1],
    'y': [0, 1, 0, 1],
    'z': [0, 1, 2, 3],
})

ggplot(df) + geom_contour(aes('x', 'y', z='z')) + coord_fixed()

Output:

Data grid must be at least 2 columns wide (was 1)

Reordering the rows (e.g. by sorting) makes the plot work. For example:

ggplot(df.sort_values(by=["y", "x"])) + geom_contour(aes('x', 'y', z='z')) + coord_fixed()

output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions