Plots.jl: Axis limits aligning with ticks

Created on 22 Aug 2019  路  10Comments  路  Source: JuliaPlots/Plots.jl

As discussed here, the automatic choice of axis limits doesn't align with the automatic choice of axis ticks. I think the limits ending at an axis tick would be an improvement.

Documentation enhancement

Most helpful comment

I'm not sure this is a good idea in general. I think it is rather up to personal taste if that is an improvement or not.

I think you know that you can provide ticks and axis limits manually to ensure this.
Alternatively you could also specifiy the number of desired ticks by passing an Int to ticks. In that case the axes limits always correspond to the last ticks:

plot(sin, -蟺, 蟺, xticks = 5, yticks = 7)

tickslimits

All 10 comments

I'm not sure this is a good idea in general. I think it is rather up to personal taste if that is an improvement or not.

I think you know that you can provide ticks and axis limits manually to ensure this.
Alternatively you could also specifiy the number of desired ticks by passing an Int to ticks. In that case the axes limits always correspond to the last ticks:

plot(sin, -蟺, 蟺, xticks = 5, yticks = 7)

tickslimits

Interesting, I didn't know that. Considering that's already behaviour, would it be an idea to add a kwarg for it, or some kind of default placeholder like 0 or -1? My plot axis ticks and limits depend on the data being displayed.

Also try
plot(sin, -蟺, 蟺, lims=:round)
This will expand the axis limits to round values and the tick values will be calculated from these limits
sin

@wfrgra that seems to work to some extent, but possibly not for all magnitudes?
Eg.

````
using Plots
pyplot()

time = 0:20
spend = fill(2.19e6, 21)
bar(time, spend,
title="Spend over time",
xlabel="Year",
ylabel="Spend",
yformatter=y->"$$y",
lims=:round)
````
Figure_1

You're missing lims=:round from your command there

Not sure what's going on there then. I don't have pyplot installed, but the limits are set independently of the backend so it shouldn't affect anything. With GR and your code above I get:

bar

My mistake. I have other plots which it doesn鈥檛 quite seem to be working for, trying to reproduce.

I've updated the example and believe it now demonstrates the issue.

Also, feature request: specify :round for one limit and a value for the other. Currently I believe you can only get one or the other:
plot(sin, -蟺, 蟺, xlims=(0, Inf), lims=:round)
Figure_1
plot(sin, -蟺, 蟺, lims=:round, xlims=(0, Inf))
Figure_2

plot(sin, -蟺, 蟺, xlims=(0, :round))
Error showing value of type Plots.Plot{Plots.PyPlotBackend}:
ERROR: MethodError: no method matching isfinite(::Symbol)
...

You're right, the axis doesn't always round to a number that the tick generating algorithm likes. I'll have a go at improving the match and see about allowing an override of one limit

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lstagner picture lstagner  路  5Comments

mkborregaard picture mkborregaard  路  3Comments

apalugniok picture apalugniok  路  3Comments

asinghvi17 picture asinghvi17  路  3Comments

nebuta picture nebuta  路  3Comments