|
| 1 | +r""" |
| 2 | +Vertical or horizontal bars |
| 3 | +--------------------------- |
| 4 | +The :meth:`pygmt.Figure.plot` method can plot vertical (**b**) or |
| 5 | +horizontal (**B**) bars by passing the corresponding shortcut to |
| 6 | +the ``style`` parameter. By default, *base* = 0 meaning that the |
| 7 | +bar is starting from 0. Append **+b**\[*base*] to change this |
| 8 | +value. To plot multi-band bars, please append |
| 9 | +**+v**\|\ **i**\ *ny* (for verticals bars) or **+v**\|\ **i**\ *nx* |
| 10 | +(for horizontal ones), where *ny* or *nx* indicate the total |
| 11 | +number of bands in the bar (and hence the number of values required |
| 12 | +to follow the *x,y* coordinate pair in the input). Here, **+i** |
| 13 | +means we must accumulate the bar values from the increments |
| 14 | +*dy* or *dx*, while **+v** means we get the complete values relative |
| 15 | +to base. Normally, the bands are plotted as sections of a final |
| 16 | +single bar. Use **+s** to instead split the bar into *ny* or *nx* |
| 17 | +side-by-side, individual and thinner bars. Multi-band bars require |
| 18 | +``cmap=True`` with one color per band. |
| 19 | +""" |
| 20 | + |
| 21 | +import pygmt |
| 22 | + |
| 23 | +fig = pygmt.Figure() |
| 24 | + |
| 25 | +pygmt.makecpt(cmap="roma", series=[0, 4, 1]) |
| 26 | + |
| 27 | +with fig.subplot( |
| 28 | + nrows=2, |
| 29 | + ncols=2, |
| 30 | + subsize=("8c", "4c"), |
| 31 | + frame="ag", |
| 32 | + sharey=True, |
| 33 | + sharex=True, |
| 34 | + margins=["0.5c", "0.75c"], |
| 35 | +): |
| 36 | + |
| 37 | + pen = "1.5p" |
| 38 | + with fig.set_panel(panel=0): |
| 39 | + color = "skyblue" |
| 40 | + fig.basemap(region=[0, 4, 0, 3], frame="+tvertical bars") |
| 41 | + fig.plot(x=1, y=2, style="b0.5c", color=color, pen=pen) |
| 42 | + fig.plot(x=2, y=2.5, style="b1c", color=color, pen=pen) |
| 43 | + # +b1 means that the bar is starting from y=1 here |
| 44 | + fig.plot(x=3, y=2.5, style="b0.75c+b1", color=color, pen=pen) |
| 45 | + |
| 46 | + with fig.set_panel(panel=1): |
| 47 | + color = "tomato" |
| 48 | + fig.basemap(region=[0, 4, 0, 3], frame="+thorizontal bars") |
| 49 | + fig.plot(x=1.5, y=0.5, style="B0.75c", color=color, pen=pen) |
| 50 | + fig.plot(x=3, y=1.5, style="B1c", color=color, pen=pen) |
| 51 | + # +b2 means that the bar is starting from x=2 here |
| 52 | + fig.plot(x=3.5, y=2.5, style="B0.5c+b2", color=color, pen=pen) |
| 53 | + |
| 54 | + # generate dictionary for plotting multi-band bars |
| 55 | + data = { |
| 56 | + "x1": [0.25, 1.25], |
| 57 | + "y": [1, 2], |
| 58 | + "x2": [0.65, 0.5], |
| 59 | + "x3": [0.4, 1.25], |
| 60 | + "x4": [2.25, 0.75], |
| 61 | + } |
| 62 | + |
| 63 | + with fig.set_panel(panel=2): |
| 64 | + fig.basemap(region=[0, 4, 0, 3], frame="+tstacked bars") |
| 65 | + fig.plot(data=data, style="B0.75c+i4", cmap=True, pen=pen) |
| 66 | + |
| 67 | + with fig.set_panel(panel=3): |
| 68 | + fig.basemap(region=[0, 4, 0, 3], frame="+tsplit bars") |
| 69 | + fig.plot(data=data, style="B1c+v4+s", cmap=True, pen=pen) |
| 70 | + |
| 71 | +fig.show() |
0 commit comments