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)
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))))
A bit of work can align the y axis labels, too.
3 Likes
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”):
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
.
2 Likes
Thank you for your answer. This will work splendidly, and I already have some experience using tikz with LaTeX.