Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gallery example showing the usage of vertical and horizontal bars #1521

Merged
merged 34 commits into from
Sep 14, 2022
Merged
Changes from 16 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dd0b0ca
Add a gallery example showing the usage of vertical and horizontal bars
michaelgrund Sep 18, 2021
016f249
formatting
michaelgrund Sep 18, 2021
aa89c01
remove trailing white spaces
michaelgrund Sep 18, 2021
f8f1e8b
formatting
michaelgrund Sep 18, 2021
d3d38b4
formatting
michaelgrund Sep 18, 2021
2cc5818
Merge branch 'main' into gallery-vh-bars
michaelgrund Sep 19, 2021
b6bf72e
Update examples/gallery/symbols/bars.py
michaelgrund Sep 19, 2021
412dbb9
Merge branch 'main' into gallery-vh-bars
michaelgrund Sep 20, 2021
1953ed4
add multi-band bar examples
michaelgrund Sep 20, 2021
9b88a9a
Merge branch 'main' into gallery-vh-bars
michaelgrund Oct 18, 2021
18ab445
udpate docstring
michaelgrund May 18, 2022
0859d27
Merge branch 'main' into gallery-vh-bars
michaelgrund May 18, 2022
1749d98
[format-command] fixes
actions-bot May 18, 2022
aa27e76
fix
michaelgrund May 18, 2022
9e481a3
fix docstring
michaelgrund May 18, 2022
7a6a6e5
fix docstring
michaelgrund May 18, 2022
6c68667
Apply suggestions from code review
michaelgrund May 19, 2022
a308816
Merge branch 'main' into gallery-vh-bars
michaelgrund Aug 20, 2022
5c38e37
update docstring
michaelgrund Aug 20, 2022
2e4f771
Apply suggestions from code review
michaelgrund Aug 20, 2022
dfd549d
add +b explanations
michaelgrund Aug 20, 2022
51b510e
Apply suggestions from code review
michaelgrund Aug 22, 2022
a638f70
Merge branch 'main' into gallery-vh-bars
michaelgrund Aug 22, 2022
1522c19
Apply suggestions from code review
michaelgrund Aug 23, 2022
02f7e27
Merge branch 'main' into gallery-vh-bars
michaelgrund Aug 23, 2022
d8f398a
Update bars.py
michaelgrund Aug 23, 2022
3b5912c
Remove pandas import
michaelgrund Aug 23, 2022
f456dd4
Apply suggestions from code review
michaelgrund Aug 23, 2022
9b91ba4
Apply suggestions from code review
michaelgrund Aug 25, 2022
d8861f0
Merge branch 'main' into gallery-vh-bars
michaelgrund Aug 25, 2022
9f9119a
Apply suggestions from code review
michaelgrund Aug 26, 2022
ca8fbd9
Merge branch 'main' into gallery-vh-bars
michaelgrund Aug 30, 2022
625bcca
Merge branch 'main' into gallery-vh-bars
michaelgrund Sep 2, 2022
2aa9efe
Merge branch 'main' into gallery-vh-bars
michaelgrund Sep 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions examples/gallery/symbols/bars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Vertical or horizontal bar
--------------------------
The :meth:`pygmt.Figure.plot` method can plot vertical (**b**) or
horizontal (**B**) bars by passing the corresponding shortcut to
the ``style`` parameter. To plot multi-band bars, please append
**+v**|**i** *ny* (for verticals bars) or **+v**|**i** *nx*
(for horizontal ones), where *ny* or *nx* indicate the total
number of bands in the bar. Here, **+i** means we must accumulate
the bar values from the increments *dy* or *dx*, while *+v* means
we get the complete values relative to base. Normally, the bands
are plotted as sections of a final single bar. Use **+s** to
instead split the bar into *ny* or *nx* side-by-side,
individual and thinner bars. Multi-band bars requires
``cmap=True`` with one color per band.
"""

import pandas as pd
import pygmt

fig = pygmt.Figure()

pygmt.makecpt(cmap="roma", series=[0, 4, 1])

with fig.subplot(
nrows=2,
ncols=2,
subsize=("8c", "4c"),
frame=["ag"],
sharey=True,
sharex=True,
margins=["0.5c", "0.75c"],
):

pen = "1.5p"
with fig.set_panel(panel=0):
color = "skyblue"
fig.basemap(region=[0, 4, 0, 3], frame="+tvertical")
fig.plot(x=1, y=2, style="b0.5c", color=color, pen=pen)
fig.plot(x=2, y=2.5, style="b1c", color=color, pen=pen)
fig.plot(x=3, y=2.5, style="b0.75c+b1", color=color, pen=pen)

with fig.set_panel(panel=1):
color = "tomato"
fig.basemap(region=[0, 4, 0, 3], frame="+thorizontal")
fig.plot(x=1.5, y=0.5, style="B0.75c", color=color, pen=pen)
fig.plot(x=3, y=1.5, style="B1c", color=color, pen=pen)
fig.plot(x=3.5, y=2.5, style="B0.5c+b2", color=color, pen=pen)

# generate dataframe for plotting multi-band bars
data = {
"x1": [0.25, 1.25],
"y": [1, 2],
"x2": [0.65, 0.5],
"x3": [0.4, 1.25],
"x4": [2.25, 0.75],
}
df = pd.DataFrame(data=data)

with fig.set_panel(panel=2):
fig.basemap(region=[0, 4, 0, 3], frame='+t"stacked bars"')
fig.plot(data=data, style="B0.75c+i4", cmap=True, pen=pen)

with fig.set_panel(panel=3):
fig.basemap(region=[0, 4, 0, 3], frame='+t"split bars"')
fig.plot(data=data, style="B1c+v4+s", cmap=True, pen=pen)

fig.show()