GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
747 stars 216 forks source link

Add an example for double Y-axis graph #1009

Closed seisman closed 3 years ago

seisman commented 3 years ago

image

Figure from https://www.originlab.com/doc/Origin-Help/Double-Y-Graph.

This kind of base maps are commonly seen. In GMT or PyGMT, we need to make two base maps (with same x limits but different Y limits) and plot data points separately.

This is a good gallery example, but I'm not sure which category it falls in.

core-man commented 3 years ago

A quick demo:

import pygmt
import numpy as np

x = np.linspace(1.0, 9.0, num=9)
y = x
z = x**2 + 110

fig = pygmt.Figure()
fig.plot(
    region=[0, 10, 0, 10],
    projection="X5c/5c",
    frame=["WS", "af", "x+lX", "y+lY1"],
    x=x,
    y=y,
    style="c0.2c",
    color="blue",
    label="Y1",
)
fig.plot(
    region=[0, 10, 0, 200],
    frame=["Et", "af", "y+lY2"],
    x=x,
    y=z,
    style="s0.3c",
    color="red",
    label="Y2",
)
fig.legend(position="JTL+jTL+o0.2c", box=True)
fig.show()

Screenshot from 2021-03-07 21-57-45