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

primary attribute not taking effect in nested series #1495

Closed
juliohm opened this issue Apr 23, 2018 · 10 comments
Closed

primary attribute not taking effect in nested series #1495

juliohm opened this issue Apr 23, 2018 · 10 comments

Comments

@juliohm
Copy link

juliohm commented Apr 23, 2018

Could you please confirm that the following should produce two series with the same color?

@userplot FooPlot

@recipe function f(foo::FooPlot)
  y = foo.args[1]
  x = 1:length(y)

  @series begin
    seriestype := :path
    primary := false

    x, y
  end

  seriestype --> :scatter
  
  x, 2y
end

fooplot(rand(3))

screenshot from 2018-04-23 14-53-28

I remember using it in the past, but I am not sure.

@joshday
Copy link
Contributor

joshday commented Apr 24, 2018

I believe primary=false is used for removing a series from the legend, which is what is happening in your example. Questions like this may be better suited for slack or discourse.

@juliohm
Copy link
Author

juliohm commented Apr 24, 2018

Thank you @joshday , I think this one is a real issue. I used to make use of the primary attribute for exactly that: maintain the previous style from the last plot command. It is not only about the legend. Check the example below, which still works as of today:

using Plots

x = linspace(0,1,10)

scatter(x)
plot!(x, primary=false)

screenshot from 2018-04-24 07-37-52

The color is preserved with built-in plot commands. The issue is in defining nested series in plot recipes. If there is any other way to circumvent this, I'd be happy to learn.

@mkborregaard
Copy link
Member

mkborregaard commented Apr 24, 2018

You're right @juliohm . I think this was possibly introduced by #1011 , but it's certainly an unwelcome side effect. Could you use this workaround?

@recipe function f(foo::FooPlot)
         y = foo.args[1]
         x = 1:length(y)

       @series begin
         seriestype --> :scatter
         x, 2y
       end


       @series begin
           seriestype := :path
           primary := false
           x, y
       end

       [],[]
end

@juliohm
Copy link
Author

juliohm commented Apr 24, 2018

Thank you @mkborregaard, that is a very nice solution.

@juliohm juliohm changed the title primary attribute not taking effect primary attribute not taking effect in nested series Apr 24, 2018
@juliohm
Copy link
Author

juliohm commented Apr 27, 2018

@mkborregaard the solution works nicely, except that the legend is affected. Even though the second series copies the color and style, the legend shows a different series (for the [], [] pair?) in the final plot.

@mkborregaard
Copy link
Member

Yes it seems to do that in some backends but not others. Just adding primary := false to the outermost series (`[],[]') should solve this.

@juliohm juliohm closed this as completed Mar 4, 2020
@matthieugomez
Copy link
Contributor

Still, it sounds like this should be solved. For instance, seriestype= :scatterpath now gives different colors for the dots and the lines, which was not the intent.

@mkborregaard
Copy link
Member

maybe just a question of fixing the scatterpath recipe?

@matthieugomez
Copy link
Contributor

matthieugomez commented Sep 23, 2020 via email

@mkborregaard mkborregaard reopened this Sep 23, 2020
matthieugomez added a commit to matthieugomez/Plots.jl that referenced this issue Apr 7, 2021
correct scatterpath so that color does not change (see JuliaPlots#1495). Add linearfit.
@matthieugomez
Copy link
Contributor

Can be closed now #3423

@juliohm juliohm closed this as completed Apr 11, 2021
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