8000 DOC: Update broken_barh example by timhoffm · Pull Request #29488 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

DOC: Update broken_barh example #29488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2025
Merged

Conversation

timhoffm
Copy link
Member

IMHO this is more realistic and better looking.

I've always been wondering what the previous plot should mean.

@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Jan 20, 2025
@timhoffm tim 8000 hoffm force-pushed the example-broken_barh branch 2 times, most recently from cae42c4 to 92aa1a3 Compare January 20, 2025 11:55
arrowprops=dict(facecolor='black', shrink=0.05),
fontsize=16,
horizontalalignment='right', verticalalignment='top')
ax.broken_barh(cpu_1, (5.8, 0.4))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ax.broken_barh(cpu_1, (5.8, 0.4))
# xranges, yrange
ax.broken_barh(cpu_1, (5.8, 0.4))

yes it's shown in the image, but it's an easy reference point here

Copy link
Member Author
@timhoffm timhoffm Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. After thinking about it, I've decided against adding such information for the following reaons:

In the suggested form, I feel it's not obvious that xranges, yrange map to cpu_1, (5.8, 0.4)) in the line below. This is because (1) it's not clear that the comment refers to the the args of the function and (2) the structural mapping is difficult, because yrange is spelled out in a tuple and is explicit numeric values, whereas xranges is given as a named variable.

Discarded alternatives:

  • # broken_barh(xranges, yrange): Even then, the meaning of the yrange tuple is a bit mysterious and readers would have to look up the definition. (On a side node, I'd have expected either (ymin, ymax) or (ycenter, height), but not (ymin, height)).
  • # broken_barh(xranges, (ymin, height)): That would be okish, OTOH it feels a bit stupid if we have to repeat the signature as a comment.
  • a kwarg broken_barh(cpu_1, yrange=(5.8, 0.4)): While this is instructive, I don't think people would typically use this in real applications.
  • a dedicated discussion of the API in the introduction: This feels a bit heavy.

I suppose, I'm stuggling with the API. The relevant (semantic) data are the xranges. The yrange is more or less a visual detail and should not deserve so much attention. IMHO this is a bit of a design flaw, but not solvable in the example. Therefore, I've resorted to writing the example like I would as real-world code, and leave it up to the user to look up the exact API.

Copy link
Member
@story645 story645 Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# broken_barh(xranges, (ymin, height))

I understand why you feel like it's a hack but I think signature as comment is appropriate here b/c I'm hoping it reduces the cognitive load of parsing the example by explaining what those second (feel kinda arbitrary) numbers are.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Not really convinced, but it's not worth fighting over.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@timhoffm timhoffm force-pushed the example-broken_barh branch from 92aa1a3 to 1bfadee Compare January 22, 2025 01:15
IMHO this is more realistic and better looking.

I've always been wondering what the previous plot should mean.

Note: There's precedence for a similar special-casing on polar Axes for errorbars:
https://github.com/matplotlib/matplotlib/blob/3fb9c0961b5c8d5753c88ac37c08cda58a4b7839/lib/matplotlib/axes/_axes.py#L3798
@timhoffm timhoffm force-pushed the example-broken_barh branch from 1bfadee to 64535a6 Compare January 22, 2025 08:08
@story645 story645 added this to the v3.10.0-doc milestone Jan 22, 2025
@story645 story645 merged commit 597af1c into matplotlib:main Jan 22, 2025
22 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 22, 2025
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 22, 2025
QuLogic added a commit that referenced this pull request Jan 22, 2025
…488-on-v3.10.x

Backport PR #29488 on branch v3.10.x (DOC: Update broken_barh example)
timhoffm added a commit that referenced this pull request Jan 22, 2025
…488-on-v3.10.0-doc

Backport PR #29488 on branch v3.10.0-doc (DOC: Update broken_barh example)
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jan 29, 2025
Follow-up to matplotlib#29488.

It's simpler to count upwards and use `invert_yaxis()` to order
top-to-bottom rather than counting backwards
@timhoffm timhoffm mentioned t 8000 his pull request Jan 29, 2025
5 tasks
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jan 29, 2025
Follow-up to matplotlib#29488.

It's simpler to count upwards and use `invert_yaxis()` to order
top-to-bottom rather than counting backwards
@ksunden ksunden mentioned this pull request Mar 3, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: examples files in galleries/examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0