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

DOC/Gallery example "Scatter plot with histograms": General improvements #3628

Merged
merged 17 commits into from
Nov 28, 2024

Conversation

yvonnefroehlich
Copy link
Member

@yvonnefroehlich yvonnefroehlich commented Nov 18, 2024

Description of proposed changes

This PR contains general improvements of the Gallery example "Scatter plot with histograms":

  • Introduce / use a variable for xshift and yshift to make them more flexible (but maybe reduced readability?) Feedback is welcome (:
  • Rewrap to 88 chars
  • Improve / correct a few comments

Preview: https://pygmt-dev--3628.org.readthedocs.build/en/3628/gallery/histograms/scatter_and_histograms.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 documentation Improvements or additions to documentation skip-changelog Skip adding Pull Request to changelog labels Nov 18, 2024
@yvonnefroehlich yvonnefroehlich added this to the 0.14.0 milestone Nov 18, 2024
@yvonnefroehlich yvonnefroehlich self-assigned this Nov 18, 2024
@yvonnefroehlich yvonnefroehlich added the maintenance Boring but important stuff for the core devs label Nov 19, 2024
# Note that the y-axis annotation "Counts" is shown in x-axis direction
# due to the rotation caused by horizontal=True
projection=f"X2c/{fig_width}c",
# Note that the y-axis annotations, ticks, and label "Counts" are shown in x-axis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Note that the y-axis annotations, ticks, and label "Counts" are shown in x-axis
# Note that the y-axis ticks, tick labels, and axis label "Counts" are shown in x-axis

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Strickly speaking there are no "tick labels" in GMT but it's called "annotations" 😬.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but for me the sentence as it was did not describe the content satisfactory. Maybe @GenericMappingTools/pygmt-maintainers have an opinion on that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this histogram, the region is set to be region=[ymin, ymax, 0, 0], so the vertical axis is the actual X-axis and the horizontal axis is the actual "Y-axis". So, instead of saying:

Note that the y-axis annotations, ticks, and label "Counts" are shown in x-axis direction due to the rotation caused by horizontal=True.

Maybe we should say something like:

horizontal=True plots horizontal histograms, with X/Y axes flipped. I.e., the X axis is plotted vertically and the Y axis is plotted horizontally.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably also have to update the histogram tutorial at

# Use horizontal bars
# Please note the flip of the x and y axes regarding annotations, ticks, gridlines,
# and labels
horizontal=True,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated at cead753.

Copy link
Member Author

@yvonnefroehlich yvonnefroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe we also want to allow for non-squared scatter plots, to account for different wide values ranges of x and y?

width_scat, height_scat, height_histo = 4, 4, 5 width_scat, height_scat, height_histo = 4, 8, 5
histo_squared hiso_nonsquared

Comment on lines 31 to 33
# Set plot size.
# The scatter plot is 10x10, and the histograms are 10x3 and 3x10, respectively.
width, height = 10, 3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Set plot size.
# The scatter plot is 10x10, and the histograms are 10x3 and 3x10, respectively.
width, height = 10, 3
# Set the plot size
# Here, the scatter plot is 4x8, and the histograms are 4x5 and 5x8, respectively
width_scat, height_scat, height_histo = 4, 8, 5

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the two histograms, their widths are determined by the "height" and "weight" of the scatter plot, and their heights can be any values.

I feel we can just define the dimensions for the scatter plot only, and hardcode other dimensions in the projection parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the changes in 34c8568.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's just an example to show that it's possible to generate such plots with a few lines of extra code I would not overengineer at this point. If someone needs to adjust such plot for own purposes I guess it will be straightforward.

examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
@seisman seisman added needs review This PR has higher priority and needs review. and removed maintenance Boring but important stuff for the core devs labels Nov 26, 2024
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Nov 26, 2024
@seisman
Copy link
Member

seisman commented Nov 27, 2024

@yvonnefroehlich @michaelgrund In my opinion, this PR now is ready for merging. Please give this PR a final review.

examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/tutorials/advanced/cartesian_histograms.py Outdated Show resolved Hide resolved
projection="X10c/10c",
frame=["WSrt", "a1"],
region=[xmin, xmax, ymin, ymax],
projection=f"X{width}/{height}",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to skip the unit? If we keep centimeters, we need to update a few other lines (an partly need f-strings).

Suggested change
projection=f"X{width}/{height}",
projection=f"X{width}c/{height}c",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more inclined to skip the unit if possible. For projections, it's fine to keep the unit or not, but for other parameters, e.g, xshift, skipping the unit makes more sense (i.e., xshift=width + 2, rather than xshift=f"{width + 2}c.

examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/gallery/histograms/scatter_and_histograms.py Outdated Show resolved Hide resolved
examples/tutorials/advanced/cartesian_histograms.py Outdated Show resolved Hide resolved
examples/tutorials/advanced/cartesian_histograms.py Outdated Show resolved Hide resolved
seisman and others added 2 commits November 27, 2024 19:12
Co-authored-by: Yvonne Fröhlich <[email protected]>
Co-authored-by: Michael Grund <[email protected]>
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Nov 28, 2024
@seisman seisman merged commit f8e28ce into main Nov 28, 2024
21 checks passed
@seisman seisman deleted the improve-example-scatterhisto branch November 28, 2024 03:04
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 skip-changelog Skip adding Pull Request to changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants