has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
3.92k stars 210 forks source link

Colored segments with manual group assignment breaks geom_path line endings #727

Closed bmorledge-hampton19 closed 8 months ago

bmorledge-hampton19 commented 8 months ago

I am trying to use geom_path to create a plot with multiple, continuous segments of different colors, joined by round line endings. Here is an example of some code that I would expect to achieve this:

import pandas
from plotnine import *

df = pandas.DataFrame({'x': [1, 2, 3, 4, 5, 6, 7],
                       'y': [18, 22, 19, 14, 14, 11, 20],
                       "color": ["blue", "green", "blue", "blue", "green", "green", "blue"]})

(
    ggplot(df, aes(x = 'x', y = 'y', color = "color", group = 1)) +
    geom_path(size = 2, lineend = "round") +
    scale_color_identity()
)

Unfortunately, using different colors in combination with the manual group assignment appears to break the line endings so that they are the default "butt":

image

This seems to me to be a bug, as I have used this pattern in R ggplot before and it produces the proper line endings as expected. Am I missing something obvious here? Is there a simple fix, or is this a problem that will need to be addressed in a future release?