# Grid of differently colored scatter plots

**URL:** <https://discourse.julialang.org/t/grid-of-differently-colored-scatter-plots/74202>\
**Category:** New to Julia\
**Tags:** plotting, plots\
**Created:** [January 7, 2022, 4:46pm UTC](https://discourse.julialang.org/t/grid-of-differently-colored-scatter-plots/74202 "2022-01-07T16:46:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam-srut](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adam-srut/32/32514_2.png) [@adam-srut](https://discourse.julialang.org/u/adam-srut)\
**Post date:** [January 7, 2022, 4:46pm UTC](https://discourse.julialang.org/t/grid-of-differently-colored-scatter-plots/74202/1 "2022-01-07T16:46:25Z")

</div>

Hello,  
I am trying to plot a 14x3 grid of scatter plots with common x-axes and common coloring based on their z-value (I have a vector of colors).  
My current code looks like this:

```julia
plot(layout=(14,3))
for i in 1:42
    plot!(x, y[i,:], markercolors=cols, seriestype = :scatter, subplot=i, size=(300,200))
end

```

but this overlays all the plots and returns this message:

```julia
GKS: Rectangle definition is invalid in routine SET_VIEWPORT

```

![ivct_band](https://global.discourse-cdn.com/julialang/original/3X/a/4/a41f29a39d3ef2cdabd7282af7bf6266809acc49.png)  
Do you have any solution on how to plot this many subplots with a reasonable size?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 7, 2022, 5:28pm UTC](https://discourse.julialang.org/t/grid-of-differently-colored-scatter-plots/74202/2 "2022-01-07T17:28:00Z")

</div>

`Plots.jl`’s `plotly()` backend might be helpful to handle a large number of subplots. One example:

```julia
using Measures, Plots; plotly()

function grid_scatter(N,M)
    plotsize = (M*400,N*400)
    plts = [scatter(rand(10), xlabel="X-axis ($i)", ylabel="Y-axis ($i)", color=i,
        margin = 10mm, legend=false, plotsize=(400,400), label="plot#$i") for i in 1:N*M]
    plot(plts..., layout=(N,M), size=plotsize)
end

grid_scatter(14,13)

```

Fyi, a fraction of the scrollable html file created:

 ![Plots_plotly_grid_scatter_14x13](https://global.discourse-cdn.com/julialang/original/3X/7/8/78ada33857d05ffeca4acde814f785100256b2ff.png)

---

<div class="post-metadata">

**Author:** ![adam-srut](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adam-srut/32/32514_2.png) [@adam-srut](https://discourse.julialang.org/u/adam-srut)\
**Post date:** [January 8, 2022, 2:18pm UTC](https://discourse.julialang.org/t/grid-of-differently-colored-scatter-plots/74202/3 "2022-01-08T14:18:16Z")

</div>

Thanks! This is working!  
Would you know how to export the grid to .pdf?  
Typing just:

```julia
savefig("./plots.pdf")

```

will fail like this (png gives the same result as pdf):

 ![plots](https://global.discourse-cdn.com/julialang/original/3X/8/0/80ebed153df634f9e6bfc354cd464c821d39159d.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 8, 2022, 3:02pm UTC](https://discourse.julialang.org/t/grid-of-differently-colored-scatter-plots/74202/4 "2022-01-08T15:02:36Z")

</div>

> [@adam-srut](#):
>
> Would you know how to export the grid to .pdf?

I am only able to save to html and from the browser create a PDF.

For batch processing you may consider [wkhtmltopdf](https://wkhtmltopdf.org/) freeware.
