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

abline! #125

Closed
diegozea opened this issue Feb 2, 2016 · 20 comments
Closed

abline! #125

diegozea opened this issue Feb 2, 2016 · 20 comments

Comments

@diegozea
Copy link
Contributor

diegozea commented Feb 2, 2016

Hi!
It would be great to have an abline function, similar to R.
Best,

@tbreloff
Copy link
Member

tbreloff commented Feb 2, 2016

Right now you can do hline, vline, or add a regression term with smooth. Here's some examples:

tmp

abline could be done manually of course, but I can see the use for it, so I'll leave this open.

@pkofod
Copy link
Contributor

pkofod commented Feb 2, 2016

Just to be clear, how would you create the line y=0.5+0.1*x using the mentioned functions? I mean, as abline(a=0.5, b=0.1) does.

@tbreloff
Copy link
Member

tbreloff commented Feb 2, 2016

Right now you would have to add the line manually:

tmp

@diegozea
Copy link
Contributor Author

diegozea commented Feb 2, 2016

Also you can do
plot!(0:100, x -> 0.5 + 0.1 * x, linetype=:l)
but it's annoying when you don't know the limits for x.

@tbreloff
Copy link
Member

tbreloff commented Feb 2, 2016

Or better yet: plot!([0,100], x->0.5+0.1x) which doesn't plot the [1,2,3,...,99] points.

@pkofod
Copy link
Contributor

pkofod commented Feb 2, 2016

Okay, so I just misunderstod the "could be done manually of course". So I guess something like

function abline!(a, b, ...)
    fetch x limits
    plot!([xmin, xmax], x-> b+a*x)
end

I can do a PR if this would be useful to have.

@tbreloff
Copy link
Member

tbreloff commented Feb 2, 2016

Sure if you want to give it a go... this probably belongs in recipes.jl

On Tue, Feb 2, 2016 at 10:53 AM, Patrick Kofod Mogensen <
[email protected]> wrote:

Okay, so I just misunderstod the "could be done manually of course". So I
guess something like

function abline!(a, b, ...)
fetch x limits
plot!([xmin, xmax], x-> b+a*x)end

I can do a PR if this would be useful to have.


Reply to this email directly or view it on GitHub
#125 (comment).

@tbreloff
Copy link
Member

tbreloff commented Feb 2, 2016

Please merge the PR into the dev branch, not master. It makes my flow a
little easier. Thanks!

On Tue, Feb 2, 2016 at 11:03 AM, Tom Breloff [email protected] wrote:

Sure if you want to give it a go... this probably belongs in recipes.jl

On Tue, Feb 2, 2016 at 10:53 AM, Patrick Kofod Mogensen <
[email protected]> wrote:

Okay, so I just misunderstod the "could be done manually of course". So I
guess something like

function abline!(a, b, ...)
fetch x limits
plot!([xmin, xmax], x-> b+a*x)end

I can do a PR if this would be useful to have.


Reply to this email directly or view it on GitHub
#125 (comment).

@joshday
Copy link
Contributor

joshday commented Feb 2, 2016

Could there be a method for plotting a function which takes the x limits from the current plot? It's a common use case, and a little more flexible than abline. plot!(x -> .5 + .1x)

@pkofod
Copy link
Contributor

pkofod commented Feb 2, 2016

@joshday how should we then choose how to sample the domain?

@joshday
Copy link
Contributor

joshday commented Feb 2, 2016

I'm not sure I understand the question. Maybe my comment needs clarification. This already works:

scatter(randn(100))
plot!(x -> .5 + .1x, 0, 100)

Intuitively, I'd expect this to work:

scatter(randn(100))
plot!(x -> .5 + .1x)

The second two arguments for plot!(f::Function, ...) could be optional using whatever trick you're using with abline to get the maximum and minimum of current(). It'd be a very short PR. I'd be happy to add it.

@pkofod
Copy link
Contributor

pkofod commented Feb 2, 2016

My bad! I get it.

@tbreloff
Copy link
Member

tbreloff commented Feb 2, 2016

Josh this is a nice idea. To implement, you should implement this existing function: https://github.com/tbreloff/Plots.jl/blob/master/src/plot.jl#L415

Look at the other methods defined nearby if you get confused, but you just need to call the same method with an x-value.

On Feb 2, 2016, at 4:38 PM, Josh Day [email protected] wrote:

I'm not sure I understand the question. Maybe my comment needs clarification. This already works:

scatter(randn(100))
plot!(x -> .5 + .1x, 0, 100)
Intuitively, I'd expect this to work:

scatter(randn(100))
plot!(x -> .5 + .1x)
The second two arguments for plot!(f::Function, ...) could be optional using whatever trick you're using with abline to get the maximum and minimum of current(). It'd be a very short PR. I'd be happy to add it.


Reply to this email directly or view it on GitHub.

@pkofod
Copy link
Contributor

pkofod commented Feb 2, 2016

Should I add something like

xmin(plt::Plot) = minimum([minimum(plt.seriesargs[i][:x]) for i = 1:length(plt.seriesargs)])
xmax(plt::Plot) = maximum([maximum(plt.seriesargs[i][:x]) for i = 1:length(plt.seriesargs)])

in #126 if @joshday is going to look up the minimum and maximum value as well in his addition? So we avoid several different approaches of finding the min and max throughout the code.

@tbreloff
Copy link
Member

tbreloff commented Feb 2, 2016

That sounds good. It might look nicer as:

minimum([minimum(d[:x]) for d in plt.seriesargs])

(Sorry I'm such a nitpicker)

On Feb 2, 2016, at 4:53 PM, Patrick Kofod Mogensen [email protected] wrote:

Should I add something like

xmin(plt::Plot) = minimum([minimum(plt.seriesargs[i][:x]) for i = 1:length(plt.seriesargs)])
xmax(plt::Plot) = maximum([maximum(plt.seriesargs[i][:x]) for i = 1:length(plt.seriesargs)])
in #126 if @joshday is going to look up the minimum and maximum value as well in his addition? So we avoid several different approaches of finding the min and max throughout the code.


Reply to this email directly or view it on GitHub.

@pkofod
Copy link
Contributor

pkofod commented Feb 2, 2016

Much better, please nitpick - it's partly why I like to contribute where I cannot just commit myself - to learn from and be inspired by others more skilled than me.

@tbreloff
Copy link
Member

tbreloff commented Feb 2, 2016

Cool. And to add to the convenience, maybe implement "Base.extrema(plt::Plot) = ..."

On Feb 2, 2016, at 5:18 PM, Patrick Kofod Mogensen [email protected] wrote:

Much better, please nitpick - it's partly why I like to contribute where I cannot just commit myself - to learn from and be inspired by others more skilled than me.


Reply to this email directly or view it on GitHub.

@pkofod
Copy link
Contributor

pkofod commented Feb 3, 2016

abline! Is now on the dev branch @diegozea .

@tbreloff
Copy link
Member

tbreloff commented Feb 3, 2016

The relevant PR is #126.

@tbreloff tbreloff closed this as completed Feb 3, 2016
@diegozea
Copy link
Contributor Author

diegozea commented Feb 3, 2016

¡That's great! Thanks @pkofod :D

Jonas-a-Zimmermann pushed a commit to Jonas-a-Zimmermann/Plots.jl that referenced this issue Oct 29, 2024
remove DataFrames dependency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants