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

Expand histogram gallery example to show usage of pattern as fill #2421

Closed
wants to merge 11 commits into from

Conversation

michaelgrund
Copy link
Member

@michaelgrund michaelgrund commented Mar 14, 2023

Description of proposed changes

Adresses #2323 and expands the histogram example to show the use of a pattern as fill.

Preview: https://pygmt-dev--2421.org.readthedocs.build/en/2421/gallery/histograms/histogram.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 commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@michaelgrund michaelgrund added the documentation Improvements or additions to documentation label Mar 14, 2023
@michaelgrund michaelgrund added this to the 0.9.0 milestone Mar 14, 2023
@michaelgrund
Copy link
Member Author

/format

@michaelgrund michaelgrund changed the title Expand histogram gallery example Expand histogram gallery example to show usage of pattern as fill Mar 14, 2023
@seisman
Copy link
Member

seisman commented Mar 14, 2023

I'm OK with the changes, but I feel it would be better if we can generate two different random datasets and plot two overlapping histograms, just like @JingHuiTong's example in #2323 (comment):
image
The example also shows how to add legends for multiple histograms.

@michaelgrund
Copy link
Member Author

I'm OK with the changes, but I feel it would be better if we can generate two different random datasets and plot two overlapping histograms, just like @JingHuiTong's example in #2323 (comment): image The example also shows how to add legends for multiple histograms.

I'm fine with that changes although I'm not a big fan of overlapping histograms (even if pattern and color is used to distinguish them). What do others think @GenericMappingTools/pygmt-maintainers ?

@yvonnefroehlich yvonnefroehlich added the enhancement Improving an existing feature label Mar 14, 2023
@maxrjones maxrjones mentioned this pull request Mar 14, 2023
36 tasks
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
@seisman
Copy link
Member

seisman commented Mar 17, 2023

I'm OK with the changes, but I feel it would be better if we can generate two different random datasets and plot two overlapping histograms, just like @JingHuiTong's example in #2323 (comment): image The example also shows how to add legends for multiple histograms.

I'm fine with that changes although I'm not a big fan of overlapping histograms (even if pattern and color is used to distinguish them). What do others think @GenericMappingTools/pygmt-maintainers ?

Overlapping histograms are sometimes necessary and useful (e.g., comparing earthquake depth distributions of an initial catalog and a relocated catalog). But I agree that a gallery example for a simple histogram is still necessary.

What about keeping the current gallery example unchanged (i.e., closing this PR without merging. Sorry for that.) and having another gallery example for overlapping histograms filled with patterns?

@yvonnefroehlich
Copy link
Member

I'm OK with the changes, but I feel it would be better if we can generate two different random datasets and plot two overlapping histograms, just like @JingHuiTong's example in #2323 (comment). The example also shows how to add legends for multiple histograms.

I'm fine with that changes although I'm not a big fan of overlapping histograms (even if pattern and color is used to distinguish them). What do others think @GenericMappingTools/pygmt-maintainers ?

Overlapping histograms are sometimes necessary and useful (e.g., comparing earthquake depth distributions of an initial catalog and a relocated catalog). But I agree that a gallery example for a simple histogram is still necessary.

What about keeping the current gallery example unchanged (i.e., closing this PR without merging. Sorry for that.) and having another gallery example for overlapping histograms filled with patterns?

In general, I prefer non-overlapping histograms. But probably it is fair to show how this histogram type can be generated.

Maybe a tutorial on histograms beside this gallery example is a solution herer? In a tutorial, we can show the different fill options for the bars, but also how to create cumulative, overlapping, grouped, stacked, horizontal etc. histograms (here as subplot to not post several figues). Maybe we can also state limitations or concerns regarding this kind of visualizations?
histo_versions

click to show the code

import numpy as np
import pygmt

np.random.seed(100)

# Generate random elevation data from a normal distribution
mean = 100  # mean of distribution
stddev = 20  # standard deviation of distribution
data01 = mean + stddev * np.random.randn(50)
data02 = mean + stddev*2 * np.random.randn(50)
data_merge = np.concatenate((data01, data02), axis=None)

R_histo = [0, 300, 0, 51]
bin_histo = 10

fig = pygmt.Figure()

with fig.subplot(
    nrows=2,
    ncols=3,
    figsize=("20c", "10c"),
    title="Histograms",
    frame=["WSne", "xaf10", "ya10"],
    sharex="b+lElevation in m",
    sharey="l+lConunts",
):
    
    with fig.set_panel(panel=0):
        fig.histogram(
            data=data01,
            region=R_histo,
            series=bin_histo,
            fill="red3",
            pen="1p",
            histtype=0,
            label="data01"
        )
        fig.legend()

    with fig.set_panel(panel=1):
        fig.histogram(
            data=data02,
            region=R_histo,
            series=bin_histo,
            fill="orange",
            pen="1p",
            histtype=0,
            label="data02",
        )
        fig.legend()

    with fig.set_panel(panel=2):
        fig.histogram(
            data=data01,
            region=R_histo,
            series=bin_histo,
            fill="red3",
            pen="1p",
            histtype=0,
        )
        fig.histogram(
            data=data02,
            region=R_histo,
            series=bin_histo,
            fill="orange@50",
            pen="1p",
            histtype=0,
            label="overlapping",
        )
        fig.legend()

    with fig.set_panel(panel=3):
        fig.histogram(
            data=data01,
            region=R_histo,
            series=bin_histo,
            fill="red3",
            pen="1p",
            histtype=0,
            label="data01"
        )
        fig.histogram(
            data=data01,
            region=R_histo,
            series=bin_histo,
            fill="p8+b",
            pen="1p",
            histtype=0,
            cumulative=True,
            label="cumulative"
        )
        fig.legend()

    with fig.set_panel(panel=4):
        fig.histogram(
            data=data_merge,
            region=R_histo,
            series=bin_histo,
            fill="orange",
            pen="1p",
            histtype=0,
            label="stacked",
        )
        fig.histogram(
            data=data01,
            region=R_histo,
            series=bin_histo,
            fill="red3",
            pen="1p",
            histtype=0,
        )
        fig.legend()

    with fig.set_panel(panel=5):
        fig.histogram(
            data=data01,
            region=R_histo,
            series=bin_histo,
            fill="red3",
            pen="1p",
            histtype=0,
            barwidth=str(bin_histo/2) + "+o-" + str(bin_histo/4),
        )
        fig.histogram(
            data=data02,
            region=R_histo,
            series=bin_histo,
            fill="orange",
            pen="1p",
            histtype=0,
            barwidth=str(bin_histo/2) + "+o" + str(bin_histo/4),
            label="grouped",
        )
        fig.legend()
    
fig.show()
# fig.savefig(fname="histo_versions.png")

I am fine with not expanding this gallery example. But in case we still want to do so, would this be an option? I feel here the overlapping is visually not misleading.
Code example: (so far, only code, no comments)

import numpy as np
import pygmt

np.random.seed(100)

# Generate random elevation data from a normal distribution
mean = 100  # mean of distribution
stddev = 20  # standard deviation of distribution
data = mean + stddev * np.random.randn(50)

region_histo = [0, 200, 0, 51]
bin_histo = 10

fig = pygmt.Figure()

with fig.subplot(
    nrows=1,
    ncols=2,
    figsize=("20c", "10c"),
    title="Histograms",
    frame=["WSne", "xaf10", "ya10"],
    sharex="b+lElevation in m",
    sharey="l+lConunts",
):
    
    with fig.set_panel(panel=0):
        fig.histogram(
            data=data,
            region=region_histo,
            series=bin_histo,
            fill="red3",
            pen="1p",
            histtype=0,
        )

    with fig.set_panel(panel=1):
        fig.histogram(
            data=data,
            region=region_histo,
            series=bin_histo,
            fill="red3",
            pen="1p",
            histtype=0,
            label="data",
        )
        fig.histogram(
            data=data,
            region=region_histo,
            series=bin_histo,
            fill="p8+b",
            pen="1p",
            histtype=0,
            cumulative=True,
            label="data cumulative",
        )
        fig.legend(position="jLT")
    
fig.show()
# fig.savefig(fname="histo_cumulative.png")

Output figure:
histo_cumulative

@seisman
Copy link
Member

seisman commented Mar 17, 2023

Maybe a tutorial on histograms beside this gallery example is a solution herer? In a tutorial, we can show the different fill options for the bars, but also how to create cumulative, overlapping, grouped, stacked, horizontal etc. histograms (here as subplot to not post several figues). Maybe we can also state limitations or concerns regarding this kind of visualizations?

A tutorial for histograms is definitely a good idea, although writing a tutorial usually takes more time than writing an example.

@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Mar 18, 2023

Maybe a tutorial on histograms beside this gallery example is a solution herer? In a tutorial, we can show the different fill options for the bars, but also how to create cumulative, overlapping, grouped, stacked, horizontal etc. histograms (here as subplot to not post several figues). Maybe we can also state limitations or concerns regarding this kind of visualizations?

A tutorial for histograms is definitely a good idea, although writing a tutorial usually takes more time than writing an example.

I would be pleased to work on such a histogram tutorial. @michaelgrund are you fine with this?

Regarding this gallery example I have currently unfortunately no better / other ideas as those I have already posted 🙁.

michaelgrund and others added 2 commits March 20, 2023 11:13
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed enhancement Improving an existing feature labels Mar 20, 2023
@yvonnefroehlich
Copy link
Member

yvonnefroehlich commented Mar 20, 2023

Maybe a tutorial on histograms beside this gallery example is a solution herer? In a tutorial, we can show the different fill options for the bars, but also how to create cumulative, overlapping, grouped, stacked, horizontal etc. histograms (here as subplot to not post several figues). Maybe we can also state limitations or concerns regarding this kind of visualizations?

A tutorial for histograms is definitely a good idea, although writing a tutorial usually takes more time than writing an example.

I would be pleased to work on such a histogram tutorial. @michaelgrund are you fine with this?

Great! I started working on a tutorial regarding cartesian histograms in PR #2445.

michaelgrund and others added 3 commits March 21, 2023 09:13
@weiji14
Copy link
Member

weiji14 commented Mar 23, 2023

So, what's the decision for this PR? Are we keeping the original 1-histogram example and closing this PR in favour of #2445?

@yvonnefroehlich
Copy link
Member

So, what's the decision for this PR? Are we keeping the original 1-histogram example and closing this PR in favour of #2445?

Thanks for asking @weiji14! Hm. I am also a bit unsure at the moment 🙈. I thought, plotting the same histogram with a pattern is a bit too simple (please see #2323 (comment)). But after @seisman approved this PR now, it looked like we keep the changes as is 😂. As already mentioned, I am fine with both ways. Regarding showing a histogram with overlapping bars (please see #2421 (comment)), I posted an alternative plot (please see #2421 (comment)). Here, I feel overlaid bars are visually OK and not misleading (see comment #2421 (comment)). However, this figure, is currently also / now used in the tutorial (please see PR #2445). @michaelgrund, as this is your PR, how do you feel you / we want to continue here 🙂?

@seisman
Copy link
Member

seisman commented Mar 23, 2023

So, what's the decision for this PR? Are we keeping the original 1-histogram example and closing this PR in favour of #2445?

Thanks for asking @weiji14! Hm. I am also a bit unsure at the moment 🙈. I thought, plotting the same histogram with a pattern is a bit too simple (please see #2323 (comment)). But after @seisman approved this PR now, it looked like we keep the changes as is 😂. As already mentioned, I am fine with both ways. Regarding showing a histogram with overlapping bars (please see #2421 (comment)), I posted an alternative plot (please see #2421 (comment)). Here, I feel overlaid bars are visually OK and not misleading (see comment #2421 (comment)). However, this figure, is currently also / now used in the tutorial (please see PR #2445). @michaelgrund, as this is your PR, how do you feel you / we want to continue here 🙂?

Although I approved this PR, I still prefer the original 1-histogram example, which is much simpler than the current two-subplot example.

@michaelgrund
Copy link
Member Author

Fine with closing this PR.

@michaelgrund michaelgrund removed the final review call This PR requires final review and approval from a second reviewer label Mar 24, 2023
@seisman seisman deleted the gallery-hist-pattern branch March 24, 2023 12:17
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.

5 participants