Skip to content

Commit adf5e4d

Browse files
Add logarithmic and power projections (#742)
1 parent 9c357f3 commit adf5e4d

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

examples/projections/nongeo/cartesian.py renamed to examples/projections/nongeo/cartesian_linear.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
Cartesian
3-
=========
2+
Cartesian linear
3+
================
44
55
``Xwidth/[height]``: Give the ``width`` of the figure and the optional argument ``height``.
66
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Cartesian logarithmic
3+
=====================
4+
5+
``xwidth[l]/[height[l]]``: Give the ``width`` of the figure and the optional argument \
6+
``height``. The axis or axes with a logarithmic transformation requires ``l`` after
7+
its size argument.
8+
"""
9+
import numpy as np
10+
import pygmt
11+
12+
# Create a list of x values 0-100
13+
xline = np.arange(0, 101)
14+
# Create a list of y-values that are the square root of the x-values
15+
yline = xline ** 0.5
16+
# Create a list of x values for every 10 in 0-100
17+
xpoints = np.arange(0, 101, 10)
18+
# Create a list of y-values that are the square root of the x-values
19+
ypoints = xpoints ** 0.5
20+
21+
fig = pygmt.Figure()
22+
fig.plot(
23+
region=[1, 100, 0, 10],
24+
# Set a logarithmic transformation on the x-axis
25+
projection="X15cl/10c",
26+
# Set the figures frame, color, and gridlines
27+
frame=["WSne+gbisque", "x2g3", "ya2f1g2"],
28+
x=xline,
29+
y=yline,
30+
# Set the line thickness to *1p*, the color to *blue*, and the style to *dash*
31+
pen="1p,blue,-",
32+
)
33+
# Plot square root values as points on the line
34+
# Style of points is 0.3 cm square, color is *red* with a *black* outline
35+
# Points are not clipped if they go off the figure
36+
fig.plot(x=xpoints, y=ypoints, style="s0.3c", color="red", no_clip=True, pen="black")
37+
fig.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
Cartesian power
3+
===============
4+
5+
**X**\ *width*\ [**p**\ *pvalue*]/[*height*\ [**p**\ *pvalue*]]: Give the
6+
*width* of the figure and the optional argument *height*. The axis or axes with a
7+
logarithmic transformation requires **p** and the power transformation for that axis.
8+
"""
9+
import numpy as np
10+
import pygmt
11+
12+
# Create a list of y values 0-10
13+
yvalues = np.arange(0, 11)
14+
# Create a list of x-values that are the square of the y-values
15+
xvalues = yvalues ** 2
16+
17+
fig = pygmt.Figure()
18+
fig.plot(
19+
region=[0, 100, 0, 10],
20+
# Set the power transformation of the x-axis, with a power of 0.5
21+
projection="X15cp0.5/10c",
22+
# Set the figures frame, color, and gridlines
23+
frame=["WSne+givory", "xa1p", "ya2f1"],
24+
# Set the line thickness to *thick*
25+
# Use the default color *black* and the default style *solid*
26+
pen="thick",
27+
x=xvalues,
28+
y=yvalues,
29+
)
30+
# Plot x,y values as points on the line
31+
# Style of points is 0.2 cm circles, color is *green* with a *black* outline
32+
# Points are not clipped if they go off the figure
33+
fig.plot(x=xvalues, y=yvalues, style="c0.2c", color="green", no_clip=True, pen="black")
34+
fig.show()

0 commit comments

Comments
 (0)