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

Weird stacking of layers #1391

Closed
montyvesselinov opened this issue Jan 30, 2020 · 3 comments · Fixed by #1459
Closed

Weird stacking of layers #1391

montyvesselinov opened this issue Jan 30, 2020 · 3 comments · Fixed by #1459

Comments

@montyvesselinov
Copy link

montyvesselinov commented Jan 30, 2020

The code is complicated so I cannot give you a simple breaking example. However, in essence, I plot a series of gray curves and a single red curve. However, when the curves are plotted the red curve is sometimes behind and sometimes in front of the gray layers. How is this possible?!

image

the code is something like this:

colormap =
function(nc)
[Gadfly.parse_colorant(["red"]); repeat(Gadfly.parse_colorant(["gray"]), inner=nc-1)]
end
pS = Gadfly.plot(X, x=repeat(xaxis, inner=nS), y=Gadfly.Col.value(1:nS...), color=colindex, group=colindex, Gadfly.Scale.color_discrete(colormap))

What I can potentially do to avoid this from hqppening?!

@Mattriks
Copy link
Member

I can reproduce this by inserting a NaN into the matrix X:

x = 0.001:0.01:10
n = length(x)
y = advdiff.(x) # a custom function to generate y
X = hcat(50y+randn(n), 50y+0.4*randn(n), 50y+0.3*randn(n))
 X[500,1] = NaN

ci = Col.index(1:3...)
plot(X, x=repeat(x, inner=3), y=Col.value(1:3...), color=ci, Geom.line,
    Scale.color_discrete)

iss1391

A workaround would be to remove the row with NaN (or missing).
A long-term fix might be better done in Compose.jl than in Gadfly, but I'll investigate.

@Mattriks
Copy link
Member

I opened an issue in Compose (GiovineItalia/Compose.jl#384), which is a first step towards fixing the above issue. The issue here is that in Gadfly, Geom.line contains a patch which works generically for NaNs and Missing values, but to do so, the line containing NaNs or Missing values is split into two lines (plotted separately), rather than keeping (or creating) a single line with a NaN.

@montyvesselinov
Copy link
Author

@Mattriks You nailed it. I really had NaN's in the dataset. I was suspecting that they cause this behavior but i was not sure!!! Thank you very much!!!

My short term solution was to plot all the gray lines first because they did not have NaNs and plot the red line (with NaN's) last.

@Mattriks Mattriks mentioned this issue Jun 21, 2020
6 tasks
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

Successfully merging a pull request may close this issue.

2 participants