GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
747 stars 216 forks source link

Second dataset not plotting on horizontal histogram #3049

Closed ev-anderson closed 7 months ago

ev-anderson commented 7 months ago

Description of the problem

Hello,

I am trying to plot 2 datasets on a histogram horizontally, however the second dataset seems to keep getting covered by the first despite the histogram call for the first dataset occurring before. The first dataset is larger and should be plotted first so as not to cover the second dataset. I've been able to see both datasets plot in the following conditions:

I have not been able to see the second dataset plot for the following:

I've tried looking for the man pages to see if perhaps I am missing some flag, but could not find anything. Any ideas what the issue might be?

Below are the output plots from the respective conditions I stated above.

depth_hist depth_hist1 depth_hist2 depth_hist3

Minimal Complete Verifiable Example

fig = pygmt.Figure()
pygmt.config(FONT_ANNOT_PRIMARY="12p,Helvetica")
pygmt.config(MAP_FRAME_PEN="thick,black")
pygmt.config(FONT_ANNOT_SECONDARY="12p,Helvetica")
pygmt.config(FONT_LABEL="14p,Helvetica")

fig.histogram(
    data=dataset1,
    projection="X3i/-2i",
    frame=["WSne", 'x+l"Depth, km"', 'ya2000+l"Number of Events"+a0'],
    series=bar_wid1,
    fill="gray0",
    pen="1p,gray0",
    horizontal=True,
    histtype=0,
)

fig.histogram(
    data=dataset2,
    series=bar_wid2,
    fill="gray100",
    pen=".5p,gray50",
    histtype=0,
    horizontal=True,   
)

fig.show()

Full error message

No response

System information

PyGMT information:
  version: v0.5.0
System information:
  python: 3.7.11 (default, Jul 27 2021, 07:03:16)  [Clang 10.0.0 ]
  executable: /opt/anaconda3/bin/python
  machine: Darwin-21.6.0-x86_64-i386-64bit
Dependency information:
  numpy: 1.21.5
  pandas: 1.3.4
  xarray: 0.20.1
  netCDF4: 1.6.2
  packaging: 22.0
  ghostscript: 9.53.3
  gmt: 6.4.0
GMT library information:
  binary dir: /opt/anaconda3/bin
  cores: 8
  grid layout: rows
  library path: /usr/local/Cellar/gmt/6.4.0_1/lib/libgmt.dylib
  padding: 2
  plugin dir: /usr/local/Cellar/gmt/6.4.0_1/lib/gmt/plugins
  share dir: /usr/local/Cellar/gmt/6.4.0_1/share/gmt
  version: 6.4.0
welcome[bot] commented 7 months ago

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

yvonnefroehlich commented 7 months ago

Thanks @ev-anderson for writing up this detailed report! Looking at your code, I see you are not specifying the region parameter, when plotting the first histogram. As I do not have your input data, I wrote an example with random numbers. Btw we have just released PyGMT v0.11.0 🙂.

import numpy as np
import pygmt

# Sample data
rng = np.random.default_rng(seed=100)
mean = 100
stddev = 20
data01 = rng.normal(loc=mean, scale=stddev, size=42)
data02 = rng.normal(loc=mean, scale=stddev * 2, size=42)

# Create new figure instance
fig = pygmt.Figure()

# Create histogram for data01
fig.histogram(
    region=[0, 200, 0, 12],
    # Automatic range determination does not work for overlaid horizontal histograms
    # region=[0, 200, 0, 0], 
    projection="X10c",
    frame=["WSne", "xaf10", "ya1f1+lCounts"],
    data=data01,
    series=10,
    fill="black",
    histtype=0,
    label="data01",
    horizontal=True,
)

# Plot histogram for data02 on top of the histogram for data01
fig.histogram(
    data=data02,
    series=5,
    fill="white",
    pen="1p,darkgray,solid",
    histtype=0,
    label="data02",
    horizontal=True,
)

fig.legend()
fig.show()
# fig.savefig(fname="histogram_overlaid_horizontal.png")
vertical horizontal
histogram_overlaid_vertical histogram_overlaid_horizontal
seisman commented 7 months ago

I'm closing the issue since @yvonnefroehlich can't reproduce it. Please reopen it if you can provide a minimal example with datasets.