# Relative barmode in PGFPlotsX.jl

**URL:** <https://discourse.julialang.org/t/relative-barmode-in-pgfplotsx-jl/68095>\
**Category:** General Usage\
**Tags:** plotting, pgfplot, pgfplotsx\
**Created:** [September 13, 2021, 12:44pm UTC](https://discourse.julialang.org/t/relative-barmode-in-pgfplotsx-jl/68095 "2021-09-13T12:44:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [September 13, 2021, 12:44pm UTC](https://discourse.julialang.org/t/relative-barmode-in-pgfplotsx-jl/68095/1 "2021-09-13T12:44:19Z")

</div>

Hi,

I am trying to make a bar chart in PGFPlotsX.jl with the same properties of the [PlotlyJS bar charts with relative barmode](https://plotly.com/javascript/bar-charts/#bar-chart-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.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 13, 2021, 8:09pm UTC](https://discourse.julialang.org/t/relative-barmode-in-pgfplotsx-jl/68095/2 "2021-09-13T20:09:42Z")

</div>

How about:

```julia
@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)])),
)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/d/9dedd4f79c41c6d20f8b99200ccaf77d267f37d6.png)

---

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [September 18, 2021, 1:26am UTC](https://discourse.julialang.org/t/relative-barmode-in-pgfplotsx-jl/68095/3 "2021-09-18T01:26:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [September 18, 2021, 7:42am UTC](https://discourse.julialang.org/t/relative-barmode-in-pgfplotsx-jl/68095/4 "2021-09-18T07:42:07Z")

</div>

This is one way to do it:

```julia
@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](https://global.discourse-cdn.com/julialang/original/3X/6/0/60290e52734efa0262d19963544e44ffbd7e41e3.png)

---

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [September 18, 2021, 2:43pm UTC](https://discourse.julialang.org/t/relative-barmode-in-pgfplotsx-jl/68095/5 "2021-09-18T14:43:04Z")

</div>

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