-
Notifications
You must be signed in to change notification settings - Fork 216
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
Add gallery example for Figure.ternary method #2138
Conversation
Co-authored-by: Dongdong Tian <seisman.info@gmail.com> Co-authored-by: Will Schlitzer <schlitzer90@gmail.com>
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Currently running the example does not work. The issue is related to the input data. Right now it's loaded as pd.DataFrame which leads to a dying kernel when using it e.g. in a jupyter notebook. However, when converting to a numpy array via |
I set up different
Currently, I do not understand and can not explain why this happens. The issue occurs on both Windows and Linux using a dev version of PyGMT and GMT 6.4.0 (please see error message and system information below). Code example import pygmt
import pandas as pd
#-----------------------------------------------------------------------------
# (I) first rows of dataset "rock_compositions"
dict_self = {'a': [0.160, 0.220, 0.090, 0.660],
'b': [0.331, 0.625, 0.180, 0.258],
'c': [0.509, 0.158, 0.732, 0.078],
'd': [9.344, 39.156, 2.621, 12.062]}
df_self = pd.DataFrame(data=dict_self)
sum_rows = df_self.a + df_self.b + df_self.c
print(sum_rows) # not exactly 1, i.e., 100 %, for all rows
print(df_self.d)
# -> FAILS
# (II) e.g., column "d" with integer values
dict_self = {'a': [0.160, 0.220, 0.090, 0.660],
'b': [0.331, 0.625, 0.180, 0.258],
'c': [0.509, 0.158, 0.732, 0.078],
'd': [9, 39, 2, 12]}
df_self = pd.DataFrame(data=dict_self)
print(df_self.d)
# -> WORKS
# (III) e.g., change first value in column "d" to float
dict_self = {'a': [0.160, 0.220, 0.090, 0.660],
'b': [0.331, 0.625, 0.180, 0.258],
'c': [0.509, 0.158, 0.732, 0.078],
'd': [9.0, 39, 2, 12]}
df_self = pd.DataFrame(data=dict_self)
print(df_self.d)
# -> FAILS
#%%
#-----------------------------------------------------------------------------
# create Cartesian scatter plot
# for controll - WORKS for all pandas DataFrames
fig = pygmt.Figure()
# set up colormap
pygmt.makecpt(cmap="batlow", series=[0, 80, 1])
fig.plot(
df_self,
region=[0, 1, 0, 1],
projection="X10c",
style="c",
cmap=True,
pen="1p,black",
frame=["afg", "+givory"],
incols=[0, 1, 3, 2],
)
fig.show()
#-----------------------------------------------------------------------------
# create ternary diagram
# a, b, c axes be positive in a counter-clockwise direction
fig = pygmt.Figure()
# set up colormap
pygmt.makecpt(cmap="batlow", series=[0, 80, 10])
fig.ternary(
df_self,
region=[0, 100, 0, 100, 0, 100], # input values are all in [0,1], internally multipled with 100 to be in percent?
width="10c", # -JX
style="c0.25c",
cmap=True,
pen="1p,black",
frame=["aafg", "bafg", "cagf", "+givory"],
)
fig.show() Error message
Linux
System information
Linux
|
@PaulWessel This looks like an upstream bug in Here is a minimal example to reproduce the issue based on @yvonnefroehlich's tests in #2138 (comment). The example crashes with an error like:
import pandas as pd
import pygmt
df = pd.DataFrame(
{
"a": [0.160, 0.220, 0.090, 0.660],
"b": [0.331, 0.625, 0.180, 0.258],
"c": [0.509, 0.158, 0.732, 0.078],
"d": [9.0, 39, 2, 12],
}
)
fig = pygmt.Figure()
pygmt.makecpt(cmap="batlow", series=[0, 80, 10])
fig.ternary(
df,
region=[0, 100, 0, 100, 0, 100],
width="10c", # -JX
style="c0.25c",
cmap=True,
pen="1p,black",
frame=["aafg", "bafg", "cagf", "+givory"],
)
fig.show() |
Is the sci py ecosystem up and running on Apple Silicon now? Last time (summer/spring) it was a flop. |
As I know, all PyGMT dependencies can be installed on Apple Silicon using conda. |
OK, depending on time (Xmas here...) I will try to wipe whatever conda or miniconda I have and start from scratch and see if it now works. |
I'm bumping this PR to v0.9.0 because it's likely that codes in this PR rely on upstream changes. |
New miniconda for M1 installed and now things work. Ran the example above in Xcode and no crash but got some bad free memory message:
which is likely related to the crash @yvonnefroehlich got (on Linux). But otherwise it worked and plotted this: a6131bff354246398a7b40dced90b9c4.pdf So will have to debug through the ternary call and see what is fed in and how ternary allocates (or not) memory for the data. |
@michaelgrund The upstream issue has been fixed in upstream PRs GenericMappingTools/gmt#7171 and GenericMappingTools/gmt#7172 and the example will work with GMT 6.5. To make the example work with GMT 6.3-6.4 (so that we can merge this PR), we need to take special actions for pd.DataFrame input with GMT 6.3/6.4. See #2274 for the related PR. |
@michaelgrund I feel this example should be put in the "Symbols and markers" or "Base maps" categories instead. |
# between ternary diagram and colorbar | ||
fig.shift_origin(yshift="-1c") | ||
|
||
# Add a colorbar indicating the values given in the fourth column of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am thinking the way that ternary frame is drawn the colorer module has no way of knowing that axes was annotated so it does not add any space (or it is not in the right hidden file in the session dir). If a CLI equivalent script can be made I might be able to have a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the CLI version:
gmt begin map
gmt makecpt -Cturbo -T0/80/10
gmt ternary @ternary.txt -R0/100/0/100/0/100 -JX6i -Sc0.1c -C -LWater/Air/Limestone \
-Baafg+l"Water component"+u" %" -Bbafg+l"Air component"+u" %" -Bcagf+l"Limestone component"+u" %" \
-B+givory+t"Example data from MATLAB Central"
gmt colorbar
gmt end show
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the plot generated using the default
Figure.colorbar(frame=["x+lPermittivity"])
call. I feel the default location of the colorbar should be improved on the GMT side. What do you think?
Totally agree with you @seisman, would be great if the colorbar is placed without any direction shiftings.
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Yvonne Fröhlich <94163266+yvonnefroehlich@users.noreply.github.com>
Description of proposed changes
This PR adds a gallery example showing the usage of Figure.ternary(). Example is adopted from the corresponding GMT docs.
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