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

subplots throw away shape information #138

Closed
ashleightrinh opened this issue Sep 29, 2017 · 7 comments
Closed

subplots throw away shape information #138

ashleightrinh opened this issue Sep 29, 2017 · 7 comments

Comments

@ashleightrinh
Copy link

Is there a way to layer plots? So say I have a histogram, I want to be able to plot a line over it indicating the mean. Also maybe to have multiple histograms overlaid.

Thanks,
Ashleigh

@sglyon
Copy link
Member

sglyon commented Sep 29, 2017

Hi @ashleightrinh!

yes this is possible.

You can just add multiple traces to the plot.

here's an example:

plot([scatter(y=50 .* rand(10)), histogram(x=10 .* rand(1000))])

@ashleightrinh
Copy link
Author

ashleightrinh commented Sep 29, 2017 via email

@sglyon
Copy link
Member

sglyon commented Sep 29, 2017

Yep, check out the shapes docs: http://spencerlyon.com/PlotlyJS.jl/examples/shapes/

You are looking for using the vline function to add shapes to the layout

@asbisen
Copy link

asbisen commented Sep 29, 2017

below is a dirty sample

using PlotlyJS

x=collect(1:100)
y=rand(100)
m=mean(y)

t0=scatter(x=x, y=y)
s=[hline(m)]

plot([t0], Layout(;shapes=s))

@ashleightrinh
Copy link
Author

Thank you! I realised it does work just not when I am trying to put multiple plots next to each other. Here is the code I have

shape1 = [vline(mean(matrix1))]
shape2 = [vline(mean(matrix2))]
shape3 = [vline(mean(matrix3))]

data1 = histogram(x=matrix1, nbinsx=18)
data2 = histogram(x=matrix2, nbinsx=18)
data3 = histogram(x=matrix3, nbinsx=18)

where <matrix1>, <matrix2> and <matrix3> are of type <Array{Float64,1}>.

p1 = plot([data1], Layout(;shapes=shape1))
p2 = plot([data2], Layout(;shapes=shape2))
p3 = plot([data3], Layout(;shapes=shape3))
[p1 p2 p3]

@sglyon
Copy link
Member

sglyon commented Oct 2, 2017

I think you are right. I don't currently have logic to combine the shapes from individual plot layouts into the final "subplotted" plot.

You could try

p1 = plot([data1], Layout(;shapes=shape1))
p2 = plot([data2], Layout(;shapes=shape2))
p3 = plot([data3], Layout(;shapes=shape3))
p = [p1 p2 p3]
relayout!(p, shapes=vcat(shape1, shape2, shape3))

But I'm worried that the locations of the shapes will not be correct...

@sglyon sglyon changed the title Overlaying plots? subplots throw away shape information Dec 13, 2017
@sglyon
Copy link
Member

sglyon commented Dec 13, 2017

Looks like all issues here have been resolved except the subplots + shapes one, making this a dup of #100. Closing in favor of that issue.

@sglyon sglyon closed this as completed Dec 13, 2017
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

3 participants