Hello,
import pygmt
fig = pygmt.Figure()
with fig.subplot(nrows=1,ncols=1,subsize=("16c", "10c")):
pen = "1.5p"
with fig.set_panel(panel=0):
fill = "skyblue"
offset=0.6
colr='yellow'
fig.basemap(region=[3, 18, 0, 8], frame=['px5f5g5+u Station'])
fig.plot(x=5+offset, y=5, style="b1c", fill=fill, pen=pen)
fig.plot(x=5-offset, y=3, style="b1c", fill=colr,pen=pen)
fig.plot(x=10+offset, y=6, style="b1c", fill=fill, pen=pen)
fig.plot(x=10-offset, y=7, style="b1c", fill=colr,pen=pen)
fig.plot(x=15+offset, y=2, style="b1c", fill=fill, pen=pen)
fig.plot(x=15-offset, y=3, style="b1c", fill=colr,pen=pen)
fig.show()
How can I rename the last tick label to “20 Station” instead of “15 Station”.
Thank you
You can use Figure.text()
to add these labels.
Thank you @seisman
fig.text(text="20 Station", x=15, y=0)
What will be the y value in this case of tick label?
using custom ticks mechanism of gmt:
import pygmt
#The coord is the location of the desired annotation, tick, or grid-line,
#whereas type is a string composed of letters from
#a (annotation), i interval annotation, f frame tick, and g gridline.
#You must use either a or i within one file; no mixing is allowed.
#The coordinates should be arranged in increasing order.
#If label is given it replaces the normal annotation based on the coord value.
xannots = '''5 ag 5 Station
10 ag 10 Station
15 ag 20 Station
'''
with open('xannots.txt', 'w') as f:
f.writelines(xannots)
fig = pygmt.Figure()
with fig.subplot(nrows=1,ncols=1,subsize=("16c", "10c")):
pen = "1.5p"
with fig.set_panel(panel=0):
fill = "skyblue"
offset=0.6
colr='yellow'
fig.basemap(region=[3, 18, 0, 8], frame=['pxcxannots.txt'])
fig.plot(x=5+offset, y=5, style="b1c", fill=fill, pen=pen)
fig.plot(x=5-offset, y=3, style="b1c", fill=colr,pen=pen)
fig.plot(x=10+offset, y=6, style="b1c", fill=fill, pen=pen)
fig.plot(x=10-offset, y=7, style="b1c", fill=colr,pen=pen)
fig.plot(x=15+offset, y=2, style="b1c", fill=fill, pen=pen)
fig.plot(x=15-offset, y=3, style="b1c", fill=colr,pen=pen)
fig.savefig('custom_xticks.png', show=True)
2 Likes