WIP: Add gallery example showing how to create a stem plot#3052
WIP: Add gallery example showing how to create a stem plot#3052yvonnefroehlich wants to merge 11 commits intomainfrom
Conversation
|
/format |
|
@GenericMappingTools/pygmt-maintainers this gallery example should be ready for a first round of review 🙂. |
|
I see that you implement the stem plot using GMT's decorated lines. I'm wondering whether it would be easier to just call |
You mean something like: import numpy as np
import pygmt
# -----------------------------------------------------------------------------
# Define function to make data usable for a stem plot in PyGMT
def make_stem_data_from_xy(x, y, base=0):
x_stem = []
y_stem = []
for i_rec in range(len(x)):
x_temp = x[i_rec]
y_temp = y[i_rec]
x_stem.append(x_temp)
x_stem.append(x_temp)
x_stem.append(np.nan)
y_stem.append(0 + base)
y_stem.append(y_temp + base)
y_stem.append(np.nan)
return (x_stem, y_stem)
# -----------------------------------------------------------------------------
# Define sample data
x = np.arange(-np.pi * 4, np.pi * 4, 0.2)
y = np.sin(x * 3)
# Create new Figure instance
fig = pygmt.Figure()
size = 5
fig.basemap(region=[-size, size, -size, size], projection="X10/5c", frame=True)
x_stem, y_stem = make_stem_data_from_xy(x, y)
# Draw base line
fig.plot(x=[x_stem[0], x_stem[-2]],y=np.array([0, 0]), pen="0.5p,black")
# Plot stem lines
fig.plot(x=x_stem, y=y_stem, pen="0.5p,black,solid")
# Plot stem symbols
fig.plot(x=x, y=y, style="c0.1c", pen="1p,steelblue", fill="white", label="baseline at y=0")
fig.legend()
fig.show()I personally like to use |

Description of proposed changes
This PR is converted to draft as a high-level method is planned for creating a stem plot
This PR adds a gallery example showing how to create a stem plot in PyGMT:
Preview: https://pygmt-dev--3052.org.readthedocs.build/en/3052/gallery/lines/stem_plot.html
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Slash Commands
You can write slash commands (
/command) in the first line of a comment to performspecific operations. Supported slash command is:
/format: automatically format and lint the code