Relative barmode in PGFPlotsX.jl

Hi,

I am trying to make a bar chart in PGFPlotsX.jl with the same properties of the PlotlyJS bar charts with relative barmode. I was not able to find an example neither in the PGFPlots.jl gallery, nor in the Plots.jl documentation.

I would appreciate if someone could help me out with that. An area chart with the same “relative” effect could also work for what I need to do.

How about:

@pgf Axis(
    {ybar_stacked},
    Plot(Coordinates([(1,   1),   (2,  4), (3,  9),   (4, 16)])),
    Plot(Coordinates([(1,   6),   (2, -8), (3, -4.5), (4,  8)])),
    Plot(Coordinates([(1, -15),   (2, -3), (3,  4.5), (4, -8)])),
    Plot(Coordinates([(1,  -1),   (2,  3), (3, -3),   (4, -4)])),
)

3 Likes

Thank you. Is it possible to plot another set of coordinates in the form of a line chart on top of it?

This is one way to do it:

@pgf Axis(
    {},
    Plot({ybar_stacked, fill="blue"}, Coordinates([(1,   1),   (2,  4), (3,  9),   (4, 16)])),
    Plot({ybar_stacked, fill="red"}, Coordinates([(1,   6),   (2, -8), (3, -4.5), (4,  8)])),
    Plot({ybar_stacked, fill="gray"}, Coordinates([(1, -15),   (2, -3), (3,  4.5), (4, -8)])),
    Plot({ybar_stacked, fill="brown"}, Coordinates([(1,  -1),   (2,  3), (3, -3),   (4, -4)])),
    Plot({scatter}, Coordinates(range(1, 4; length=200), 20*rand(200).-10))
)

Screenshot 2021-09-18 at 09.41.36

3 Likes

Thank you all! PGFPlotsX.jl is really great. It gives a lot of flexibility and the best quality for research papers.

2 Likes