-
Notifications
You must be signed in to change notification settings - Fork 224
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
Conversation
/format |
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): |
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 ? |
Co-authored-by: Yvonne Fröhlich <[email protected]>
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? 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. 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") |
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 🙁. |
Co-authored-by: Yvonne Fröhlich <[email protected]>
Great! I started working on a tutorial regarding cartesian histograms in PR #2445. |
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. |
Fine with closing this PR. |
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
make format
andmake check
to 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 commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version