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

WIP: Add gallery example showing how to create a stem plot #3052

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

yvonnefroehlich
Copy link
Member

@yvonnefroehlich yvonnefroehlich commented Feb 17, 2024

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:

  • Define function to prepare the data
  • Document this function
  • Add example plot
  • Vary the appearance of the stem symbol and stem line, as well as the baseline
  • Add comments

Preview: https://pygmt-dev--3052.org.readthedocs.build/en/3052/gallery/lines/stem_plot.html

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash command is:

  • /format: automatically format and lint the code

@yvonnefroehlich yvonnefroehlich added the documentation Improvements or additions to documentation label Feb 17, 2024
@yvonnefroehlich yvonnefroehlich added this to the 0.12.0 milestone Feb 17, 2024
@yvonnefroehlich
Copy link
Member Author

/format

@yvonnefroehlich yvonnefroehlich self-assigned this Feb 18, 2024
@seisman seisman removed this from the 0.12.0 milestone Feb 26, 2024
@yvonnefroehlich yvonnefroehlich added the needs review This PR has higher priority and needs review. label Apr 13, 2024
@yvonnefroehlich
Copy link
Member Author

@GenericMappingTools/pygmt-maintainers this gallery example should be ready for a first round of review 🙂.

@seisman seisman added this to the 0.12.0 milestone Apr 15, 2024
@seisman
Copy link
Member

seisman commented Apr 15, 2024

I see that you implement the stem plot using GMT's decorated lines. I'm wondering whether it would be easier to just call plot twice, one for lines and one for symbols.

@yvonnefroehlich
Copy link
Member Author

I see that you implement the stem plot using GMT's decorated lines. I'm wondering whether it would be easier to just call plot twice, one for lines and one for symbols.

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()

stem_plot_via_twice_plot

I personally like to use plot only once. In this case, both the line and the symbol are included in the legend entry. When using plot we probably have to use two different "versions" of the data. But on the other hand side, for non-native GMT users decorated lines may be not so intuitive.

@yvonnefroehlich yvonnefroehlich removed the needs review This PR has higher priority and needs review. label Apr 18, 2024
@seisman seisman modified the milestones: 0.12.0, 0.13.0 Apr 19, 2024
@yvonnefroehlich yvonnefroehlich marked this pull request as draft April 19, 2024 15:33
@seisman seisman removed this from the 0.13.0 milestone Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants