Skip to content
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

[ENH]: Starting point/offset for (logarithmic and/or relative) bar plots #27951

Open
oscargus opened this issue Mar 20, 2024 · 3 comments
Open

Comments

@oscargus
Copy link
Contributor

Problem

I would like to create a figure similar to this:

image

where the bars starts with a given offset (in this case 1).

Clearly it can be achieved with a bit of tricks, but I would prefer if one can simply provide an offset argument to bar. For example, I am now not using a logarithmic scale (and therefore there are no logarithmic minor ticks), but rather compute the log and then hard-code the y-labels.

I imagine a similar situation where one would like the bars to start at a given value and not having a log-scale, like in relative bars.

Maybe this can be done in a better way?

(I originally thought the "bottom" argument would solve this, but after testing and reading the doc-string properly, it is clear that it solves another problem.)

Proposed solution

Add an offset argument that behaves as a reference for the bar plots.

(Or provide an example where the same effect is obtained.)

@ksunden
Copy link
Member

ksunden commented Mar 20, 2024

The fundamental problem here is that bar is parameterized by the height of the bar, and not the position of the top of the bar...

so I'm not sure an offset really helps here....

I think on a linear scale bottom is exactly what you want, but you need a negative height to get a bar to go down, and that just doesn't really work with log scale.

There are certainly a few trick you could play with transforms and such, but yeah, dealing with negative numbers on log scales is tricky, and I don't think it is solved by an offset.

@tacaswell
Copy link
Member

I don't quite understand why bottom does not solve this problem (or at least ax.bar(x, hegiht-b, bottom=b)?

import matplotlib.pyplot as plt
plt.bar(range(6), [-.5, 10, 100, 1000, 1, -.99], bottom=1)
plt.yscale('log')

so

@oscargus
Copy link
Contributor Author

I don't quite understand why bottom does not solve this problem (or at least ax.bar(x, hegiht-b, bottom=b)?

Me neither. Thanks!

I'll try to see if I can find an example that does something similar or if I should add one. Will close if found.

(Just looking at the thumbnails at the bar page didn't really give any interesting examples, but there may still be one.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants