-
Notifications
You must be signed in to change notification settings - Fork 229
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
Get x- and y- limits #906
Comments
The limits are determined automatically (plus some expansion) from the data. After the plot has been draw, you may be able to get the limits, but it is not part of the user API. I think for better advice I need to know what you need the limits for. |
Let's say that I generate a first chart where the limits are computed automatically. Then I make another chart with different data, but want to use exactly the same axes limits of the first chart. I cannot find a way to obtain this. Is there one? Clearly, I could set the limits in the first chart manually and use the same limits in the second chart, but this is far from optimal - a lot of time to fine-tune the limits on the first chart. |
A trick that will probably work forever is to use a function as if to modify the limits, but then just save the value and return the original limits. from plotnine import *
from plotnine.data import mtcars
x_limits = (0, 0)
def save_x_limits(limits):
global x_limits
x_limits = limits
return limits
p = (
ggplot(mtcars, aes("wt", "mpg"))
+ geom_point()
+ scale_x_continuous(limits=save_x_limits)
)
# Draw the plot so that we get the limits
display(p) # or p.draw() or p.show()
print(x_limits) # your treasured limits!
print((min(mtcars["wt"]), max(mtcars["wt"]))) # Expected limits for this case |
Out of curiosity, is it so hard to add a function as get_limits? |
Good idea. |
I had the same problem, because I wanted to place some annotation at exactly 90% of the y axis. (basically the same as has2k1s solution)
if you know the limits you can do something like this my x axes is a date so
of course a pure plotnine solution would be highly welcome! |
This is a more common case that requires relative positioning and one should not even mess with the limits. |
In the API I see only methods for setting the x- and the y-limits.
Is there any way to get those limits?
The text was updated successfully, but these errors were encountered: