# Subplots without gap between them

**URL:** <https://discourse.julialang.org/t/subplots-without-gap-between-them/27491>\
**Category:** Visualization\
**Tags:** pgfplotsx, inspectdr\
**Created:** [August 13, 2019, 9:30am UTC](https://discourse.julialang.org/t/subplots-without-gap-between-them/27491 "2019-08-13T09:30:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Topias\_Karjalainen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/topias_karjalainen/32/9747_2.png) [@Topias\_Karjalainen](https://discourse.julialang.org/u/Topias_Karjalainen)\
**Post date:** [August 13, 2019, 9:30am UTC](https://discourse.julialang.org/t/subplots-without-gap-between-them/27491/1 "2019-08-13T09:30:05Z")

</div>

Hi!

I’m trying to create a plotting package for plotting financial data (as an exercise, and as a tool that I need). For it to look like I want it to look, I need to plot a subplot for indicators under the main plot that shows the time series stock price data. However, when I create the subplot, there is a gap between the main plot and the subplot. Is there a way to create a the subplot without the gap, so that both plots have the same x-axis, but separate y-axis? Below is a crude drawing of what I want. I’m using the GR backend for Plots.jl package. If there is no way of doing this with GR, I’m open to changing the backend (not to Plotly, though)

 ![plot_image](https://global.discourse-cdn.com/julialang/original/2X/6/6239dbce67790998890734a2f85aef8ca3bac3d8.jpeg)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 13, 2019, 10:46am UTC](https://discourse.julialang.org/t/subplots-without-gap-between-them/27491/2 "2019-08-13T10:46:32Z")

</div>

```julia
using PGFPlotsX

x_grid = 1:10
y1 = x_grid .* 2
y2 = x_grid .* -0.1 .- 1

@pgf GroupPlot({ group_style = { group_size = "1 by 2",
                                 vertical_sep = "0pt",
                                 xticklabels_at = "edge bottom" }},
               Axis({ height = "6cm", width = "8cm", ylabel = "A"},
                    Plot({ no_marks }, Table(x_grid, y1))),
               Axis({ height = "3cm", width = "8cm", xlabel = "something", ylabel = "B" },
                    Plot({ red, only_marks },Table(x_grid, y2))))          

```

 ![plot](https://global.discourse-cdn.com/julialang/original/3X/e/2/e2f1040582b73700684d9f1298cc69f601d743b4.png)

A bit of work can align the y axis labels, too.

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [August 14, 2019, 3:43pm UTC](https://discourse.julialang.org/t/subplots-without-gap-between-them/27491/3 "2019-08-14T15:43:17Z")

</div>

InspectDR natively supports the “common x-axis + multi-strip” concept, but at the moment, it is hard-coded to have all strips the same height.

The advantage is that you can pan/zoom interactively, and the x-axis will always be common to both y subplots (or “strips”):

![image](https://global.discourse-cdn.com/julialang/original/3X/0/4/04689ba070c10a524fdffef95541cd8e200422e9.png)

```julia
using InspectDR
using Colors

function test_nogap()
	n = 100
	x = collect(1:n)
	y1 = 5 .* rand(n) .+ 10 * (1.02 .^x)
	y2 = .008 .* (1.05 .^x)

	#Color constants:
	COLOR_RED = RGB24(1, 0, 0)
	COLOR_GREEN = RGB24(0, 1, 0)
	COLOR_BLUE = RGB24(0, 0, 1)
	COLOR_YELLOW = RGB24(1, 1, 0)
	COLOR_CYAN = RGB24(0, 1, 1)

	#Using Plot2D simplified "template" constructor:
	plot = InspectDR.Plot2D(:lin, [:lin, :lin],
		title = "Some Fake Data", xlabel = "X",
		ylabels = ["Y1", "Y2"]
	)
	plot.layout[:enable_legend] = true
	plot.layout[:halloc_legend] = 150
	plot.layout[:valloc_mid] = 0

	wfrm = add(plot, x, y1, id="Noisy Model", strip=1)
		wfrm.line = line(color=COLOR_RED, width=2)
	wfrm = add(plot, x, y2, id="Exp growth", strip=2)
		wfrm.line = line(color=COLOR_BLUE, width=2)

	plot.strips[1].yext_full = InspectDR.PExtents1D(min=5, max=85)
	plot.strips[2].yext_full = InspectDR.PExtents1D(min=0, max=1.05)

	gplot = display(InspectDR.GtkDisplay(), plot)
	return gplot
end

test_nogap() #Run code

```

NOTE: the gap was removed by setting `plot.layout[:valloc_mid] = 0`.

---

<div class="post-metadata">

**Author:** ![Topias\_Karjalainen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/topias_karjalainen/32/9747_2.png) [@Topias\_Karjalainen](https://discourse.julialang.org/u/Topias_Karjalainen)\
**Post date:** [September 3, 2019, 10:06am UTC](https://discourse.julialang.org/t/subplots-without-gap-between-them/27491/4 "2019-09-03T10:06:33Z")

</div>

Thank you for your answer. This will work splendidly, and I already have some experience using tikz with LaTeX.
