# Subplot problems with histograms

**URL:** <https://discourse.julialang.org/t/subplot-problems-with-histograms/48522>\
**Category:** General Usage\
**Tags:** question, plotting, first-steps\
**Created:** [October 16, 2020, 9:46pm UTC](https://discourse.julialang.org/t/subplot-problems-with-histograms/48522 "2020-10-16T21:46:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dustin\_Hess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dustin_hess/32/11957_2.png) [@Dustin\_Hess](https://discourse.julialang.org/u/Dustin_Hess)\
**Post date:** [October 16, 2020, 9:46pm UTC](https://discourse.julialang.org/t/subplot-problems-with-histograms/48522/1 "2020-10-16T21:46:36Z")

</div>

Hi Guys trying out the PoltlyJS package. I wanted to plot the classic iris data set. I was trying to build my own pairplot. However, plotlyJS gives some strange behavior. When I subplot the histogram it no longer overlays and the binning appears to change as the height of the histogram changes.

```julia
using PlotlyJS
using CSV
using DataFrames

col_names = ["SepalLength", "SepalWidth", "PetalLength", "PetalWidth", "Class"]
iris = CSV.read("iris.csv"; header = col_names, normalizenames = true)
iris = groupby(iris, :Class)

gp_1 = iris[1]
gp_2 = iris[2][1,5]
gp_3 = iris[3][1,5]

function histo(df::GroupedDataFrame, i::Int)
    data = typeof(histogram())[]

    for k in 1:length(df)
        x = df[k][!,i]

        fields = Dict{Symbol,Any}(
            :type => "histogram",
            :x => x,
            :opacity => 0.5,
            :nbinsx => 10
        )

        trace = GenericTrace("histogram", fields)
        push!(data, trace )
    end
    return data
end

function scatt(df::GroupedDataFrame, i::Int, j::Int)
    data = typeof(scatter())[]
    col = i
    row = j

    for k in 1:length(df)
        y = df[k][!,i]
        x = df[k][!,j]
        trace = scatter(x=x, y=y; mode="markers")
        push!(data, trace)
    end
    return data
end

layout = Layout(barmode="overlay")
p1 = plot(histo(iris, 1), layout )
p2 = plot(scatt(iris,2,1))

[p1 p2]

```

If just plot the histogram you get

 ![Screenshot from 2020-10-16 16-42-16](https://global.discourse-cdn.com/julialang/original/3X/6/2/62df22718b4e345d88bed05470868fb634c31f7e.png)

If you stack subplot it via `[p1 p2]` the you get

 ![Screenshot from 2020-10-16 16-44-38](https://global.discourse-cdn.com/julialang/original/3X/3/c/3c1d400ebfef9885f306e2c75439c329715c37b3.png)

Any help would be appriciated.
