has2k1 / has2k1/plotnine

matplotlib shape tuple syntax fails for tuple of tuples

Open
#950 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement
Dominant language
Python
Stars
4.8k
Forks
254
Avg merge
10h 35m
Merged PRs (30d)
9

Description

from https://github.com/machow/plotnine-guide/pull/20, matplotlib provides a special tuple syntax for creating shapes. This includes a "tuple of tuples" syntax for drawing things. However, it seems like this fails due to pandas groupby not knowing how to sort the tuple of tuples (when other shapes are involved).

In the example below, removing house from the data works, but with it in, raises a pandas sort error (can't compare int with tuple):

# polygon: (num, 0, angle)
pentagon = (5, 0, 60)

# star: (num, 1, angle)
five_point_star = (5, 1, 60)

# astericks: (num, 2, angle)
five_point_astericks = (5, 2, 60)

# path: list[tuple(float, float)]
house = ((-2, -3), (-2, -1), (0, 0), (2, -1), (2, -3), (-2, -3))
shape = [pentagon, five_point_star, five_point_astericks, house]

shapes = pd.DataFrame(
    {
        "shape": shape,
        "x": list(range(len(shape))),
        "y": [0] * len(shape),
    }
)

(
    ggplot(shapes, aes("x", "y"))
    + geom_point(aes(shape="shape"), size=5)
    # + geom_text(aes(label="shape"), nudge_x=0.15)
    + scale_shape_identity(guide=None)
    + theme_void()
    + expand_limits(x=4.1)
)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied example with the mixed shape values through geom_point and scale_shape_identity. Trace the pandas groupby step that sorts shape values and verify the tuple-of-tuples shape no longer causes an int-versus-tuple comparison error while the other shapes still render.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, pandas, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.