Repository navigation
WIP: Improve and extend tutorial "Carthesian histograms" - #4988
yvonnefroehlich wants to merge 49 commits into
Conversation
|
I am confused about the behaviour the
import numpy as np
import pygmt
from pygmt.params import Axis, Frame
rng = np.random.default_rng(seed=100)
mean = 100
stddev = 20
data1 = rng.normal(loc=mean, scale=stddev, size=42)
args_histo = {
"region": [0, 200, 0, 0],
"projection": "X10c",
"frame": Frame(
axes="WStr",
xaxis=Axis(annot=True, tick=10),
yaxis=Axis(annot=1, tick=1, label="Counts"),
),
"data": data1,
"fill": "lightbrown",
"pen": "0.5p,gray30",
}
fig = pygmt.Figure()
fig.histogram(**args_histo, series=10)
fig.shift_origin(xshift="w+2c")
fig.histogram(**args_histo, series=[75, 120, 10])
fig.shift_origin(xshift="w+2c")
fig.histogram(**args_histo, series=np.array([50, 75, 80, 90, 100, 110, 120, 140, 180]))
fig.show() |
|
For me, using a colormap to fill the bars based on the position (mid-coordinate of the bin) or the bin count (or frequence) does not work by passing the colormap directly to the Edit 2026/11/22: Issue report upstream GMT at GenericMappingTools/gmt#9314
import numpy as np
import pygmt
from pygmt.params import Axis, Frame
rng = np.random.default_rng(seed=100)
mean = 100
stddev = 20
data1 = rng.normal(loc=mean, scale=stddev, size=42)
args_histo = {
"region": [0, 200, 0, 0],
"projection": "X10c",
"frame": Frame(
axes="WStr",
xaxis=Axis(annot=True, tick=10),
yaxis=Axis(annot=1, tick=1, label="Counts"),
),
"data": data1,
"pen": "0.5p,gray30",
"series": 10,
}
fig = pygmt.Figure()
fig.histogram(**args_histo, fill="lightbrown")
fig.shift_origin(xshift="w+2c")
fig.histogram(**args_histo, fill="position", cmap="SCM/batlow")
fig.shift_origin(xshift="w+2c")
fig.histogram(**args_histo, fill="value", cmap="SCM/batlow")
fig.show()
fig = pygmt.Figure()
fig.histogram(**args_histo, fill="lightbrown")
fig.shift_origin(xshift="w+2c")
pygmt.makecpt(cmap="SCM/batlow", series=[0, 200, 10])
fig.colorbar(frame=True)
fig.histogram(**args_histo, fill="position", cmap=True)
fig.shift_origin(xshift="w+2c")
pygmt.makecpt(cmap="SCM/batlow", series=[0, 15, 1])
fig.colorbar(frame=True)
fig.histogram(**args_histo, fill="value", cmap=True)
fig.show() |
|
Before putting more efforts into polishing all the explanations and comments, I like to ask for comments and reviews on the general structure (and the length) of the tutorial. The new structure is currently:
|
the x-range is set by the region parameter
this is expected. the x range is controlled by the region parameter |
Yes, the x-range of the plot, but regarding the bins the docs says:
For me this sounds like that for passing a list of three values, the minimum and maximum for the bins are taken from that list. But looking at the second plot above, the bars still start at 60, not at 75, and end at 150, not at 120. When using a sequence of any other length than three, the start and end of the bins are adjusted based on the first and last values of this sequence (third plot). |






Description of proposed changes
This PR aims to improve the tutorial "Carthesian histograms" based on the aspects mentioned at #4905 (comment).
The new structure consistes of four main sections:
seriesand bar fill viafillandcmapAs this tutorial is getting quite long we may want to think about splitting it into different smaller tutorials.
Fixes #4905
Patches #4965
Preview: https://pygmt-dev--4988.org.readthedocs.build/en/4988/tutorials/advanced/cartesian_histograms.html
Guidelines
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