Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: broken_barh does not handle categorical axes very well #25133

Copy link
Copy link
Open
@bmcfee

Description

@bmcfee
Issue body actions

Bug summary

When using broken_barh with a categorical (vertical) axis, there is no obvious way to specify the height of the bars. Unlike regular barh, float values do not work in the second argument position to specify heights.

You can hack it by using other categorical values (see example below), but this only works for integral heights and is generally yucky.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.broken_barh([(0, 5-0), (10, 13-10)], ('car engine', 1))
ax.broken_barh([(3, 6-3), ], ('jackhammer', 1))
ax.broken_barh([(1, 4-1), ], ('children playing', 1))

Above does not work. Substituting a categorical value (which maps to 1) does work:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

# 'jackhammer' is implicitly height=1 in this example
ax.broken_barh([(0, 5-0), (10, 13-10)], ('car engine', 'jackhammer'))
ax.broken_barh([(3, 6-3), ], ('jackhammer', 'jackhammer'))
ax.broken_barh([(1, 4-1), ], ('children playing', 'jackhammer'))

Actual outcome

ConversionError: Failed to convert value(s) to axis units: ('car engine', 1)

Expected outcome

It should be possible to specify heights by numerical values as well as / instead of categorical positions.

Additional information

For broader context, the full description of my use case is at https://discourse.matplotlib.org/t/advice-for-using-broken-bar-collections-with-categorical-axes/23171?u=brian.mcfee

Best guess for fix: set this up however it was done over in barh 🤷

Probably this also affects broken_bar (vertical) as well.

Operating system

No response

Matplotlib Version

3.6.3

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.