lets-plot icon indicating copy to clipboard operation
lets-plot copied to clipboard

`geom_contour`: error if data is not sorted properly

Open ASmirnov-HORIS opened this issue 6 months ago • 0 comments

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

ASmirnov-HORIS avatar Jul 03 '25 17:07 ASmirnov-HORIS