JuliaPlots / UnicodePlots.jl

Unicode-based scientific plotting for working in the terminal
Other
1.42k stars 77 forks source link

Add way to autolimit a plot that has been added to #365

Closed IanButterworth closed 8 months ago

IanButterworth commented 9 months ago

I find it's common to

using UnicodePlots

plt = lineplot([], [])
for x in y
   lineplot!(plt, some_x, some_y)
end
display(plt)

But this will end up with a plot with lims -1 1 even though there has been real data added to it.

It seems fair that the limits shouldn't auto change, but maybe there could be a autolims!(plt) function to call before display?

Otherwise I need to manually track the extrema of my data and set lims manually at the end.

t-bltg commented 9 months ago

Good point and idea for enhancement, I'll have a look soon.

The underlying problem is that limits are a Canvas property, and not a Plot feature.

t-bltg commented 9 months ago

I've modified the code slightly in https://github.com/JuliaPlots/UnicodePlots.jl/pull/366 to allow something like this, which is an enhancement over the current, but not quite what you want:


p = Plot(xlim=(-1, 2), ylim=(3, 10))  # set the limits beforehand
for x in y
   lineplot!(plt, some_x, some_y)
end
display(plt)
t-bltg commented 8 months ago

I have thought about this, and I don't think this will be easily implemented, because we draw on a fixed canvas.

However, one can set the limits beforehand as exposed in https://github.com/JuliaPlots/UnicodePlots.jl/issues/365#issuecomment-1867564480.