Closed WilliamEpenarandaA closed 6 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.
Perhaps you need to set the fill like fill=data_dev['SGC_depth']
.
I think there are two options to accomplish color-coding (and size-coding) (see the code example below):
x
, y
, z
, fill
(, and size
) parameters (see also the comment by @seisman)data
parameter (column order must be x/lon, y/lat, z/depth, quantity_for_color, quantity_for_size)Another aspect is that you set the size
parameter, but before you have already set a fixed size via the style
parameter.
Input data: MT-dev_inv-results.txt
import pandas as pd
import pygmt
file = "MT-dev_inv-results.txt"
cols2_use = [
"Date", "Hour_UTC", "Latitude", "Longitude", "SGC_depth",
"Lat-cent", "Lon-cent", "Mt_depth", "Variance",
"VarRed", "Pdc", "Pclvd", "Piso", "Mw_x", "Mw_y",
]
data_dev = pd.read_csv(file, usecols=cols2_use, delimiter=" ")
region = pygmt.info(
data=data_dev[["Longitude", "Latitude", "SGC_depth"]],
per_column=True,
spacing=(0.2, 0.2, 50),
)
fig = pygmt.Figure()
pygmt.makecpt(cmap="viridis", series=(100, 200, 1), continuous=None)
fig.plot3d(
x=data_dev["Longitude"],
y=data_dev["Latitude"],
z=data_dev["SGC_depth"],
fill=data_dev["SGC_depth"],
# OR
# data=data_dev[["Longitude", "Latitude", "SGC_depth", "SGC_depth"]],
cmap=True,
style="u0.15c",
region=region,
# size=data_dev["Mw_x"]*1.2, # Ignored when a fixed size via style is set
perspective=[240, 30],
zscale=-0.05,
)
fig.plot3d(
# x=data_dev["Lon-cent"],
# y=data_dev["Lat-cent"],
# z=data_dev["Mt_depth"],
# fill=data_dev["Mt_depth"],
# OR
data=data_dev[["Lon-cent", "Lat-cent", "Mt_depth", "Mt_depth"]],
cmap=True,
style="u0.3c",
region=region,
perspective=[240, 30],
zscale=-0.05,
frame=[
"WSneZ",
"xa0.2f0.1g0.1+lLongitude [°]",
"ya0.2f0.1g0.1+lLatitude [°]",
"za50f20g20+lDepth [km]",
]
)
fig.colorbar(frame=["a20f10", "y+lkm"], position="JRM")
fig.show()
Thanks for your comments. Including the line proposed by @seisman, solve the problem. I see that the input in fill parameter, need to put values of the variable used to make the correspond colorbar. I also thanks the explannation given to generate size-coding by @yvonnefroehlich
Description of the problem
Greetings,
I'm having troubles filling symbols with the colors based on a different variable using PyGMT v0.11 and GMT 6.3 plot3d commands in Ubuntu 18.04 OS. This is the same issue reported in this post https://forum.generic-mapping-tools.org/t/coloring-symbols-with-cpt-pygmt/4034. I have seen other comments, but none of them seem to work for my case.
I test the example 3d scatter plot found in the pygmt webpage and works normally. The problem appeared when I try to plot in 3d view some earthquakes and colored according to different depth values. The data is saved into a pandas dataframe,
data_dev
that have this structure:Below is the code than I'm using
The figure that it creates is the following and in the console doesn't appear any error or warning The code runs, but all the cubes plot black instead of using the color palette that I assigned in makecpt. Is there any problem or error in the code wrote to plot the image.
Thank in advance for your help!!!
PD: I attach the output to the command
pygmt.show_versions()
below:PyGMT information: version: v0.11.0 System information: python: 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:38:13) [GCC 12.3.0] executable: /home/william/anaconda3/envs/pygmt/bin/python machine: Linux-5.4.0-150-generic-x86_64-with-glibc2.27 Dependency information: numpy: 1.26.4 pandas: 2.2.2 xarray: 2024.3.0 netCDF4: 1.6.5 packaging: 24.0 contextily: None geopandas: None ipython: None rioxarray: None ghostscript: 10.03.0 GMT library information: binary version: 6.5.0 cores: 12 grid layout: rows image layout: library path: /home/william/anaconda3/envs/pygmt/lib/libgmt.so padding: 2 plugin dir: /home/william/anaconda3/envs/pygmt/lib/gmt/plugins share dir: /home/william/anaconda3/envs/pygmt/share/gmt version: 6.5.0
Minimal Complete Verifiable Example
No response
Full error message
No response
System information