-
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
Wrap plot3d #471
Wrap plot3d #471
Changes from 22 commits
b1ad5e0
e38b3f9
e7f7679
9dd3840
5a92360
b6d26ac
5569251
31e0fb7
af070de
ce3119d
79b07bf
8391169
0906faf
2a739d5
8c3bf7f
ff1c495
bd07900
cdcd259
413ff77
878a073
9dc9533
256a0a9
e47596f
37578e1
40f7120
e31344f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,52 @@ | ||||
""" | ||||
3D Scatter plots | ||||
---------------- | ||||
|
||||
The :meth:`pygmt.Figure.plot3d` method can be used to plot symbols in 3D. | ||||
In the example below, we show how the Iris flower dataset can be visualized | ||||
seisman marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
using a perspective 3-dimensional plot. The ``region`` argument has to be set | ||||
to include the :math:`x`, :math:`y`, :math:`z` axis limits in the form of | ||||
(xmin, xmax, ymin, ymax, zmin, zmax), and this can be done automatically using | ||||
:meth:`pygmt.info`. To include the z-axis stick, ``frame`` needs to be set as a | ||||
minimum to something like ``frame=["WsNeZ", "zaf"]``. Use ``perspective`` to | ||||
control the azimuth and elevation angle of the view, and ``zscale`` to adjust | ||||
the vertical exaggeration factor. | ||||
""" | ||||
|
||||
import pandas as pd | ||||
import pygmt | ||||
|
||||
# Load sample iris data, and convert 'species' column to categorical dtype | ||||
df = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv") | ||||
df["species"] = df.species.astype(dtype="category") | ||||
|
||||
# Use pygmt.info to get region bounds (xmin, xmax, ymin, ymax, zmin, zmax) | ||||
# The below example will return a numpy array like [0., 3., 4., 8., 1., 7.] | ||||
region = pygmt.info( | ||||
table=df[["petal_width", "sepal_length", "petal_length"]], # x, y, z columns | ||||
per_column=True, # report output as a numpy array | ||||
spacing="1/2/0.5", # rounds x, y and z intervals by 1, 2 and 0.5 respectively | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel that we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, forgot to handle that in #575. Should handle that (list inputs) when we complete the documentation for |
||||
) | ||||
|
||||
# Make our 3D scatter plot, coloring each of the 3 species differently | ||||
fig = pygmt.Figure() | ||||
pygmt.makecpt(cmap="cubhelix", series=(0, 3, 1)) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Instead, we should use But the colorbar annotations don't make sense to me. Perhaps another GMT bug. Note: the gridlines are not shown in GMT 6.1.1. It's a new future in GMT master (see GenericMappingTools/gmt#3993), but the gridlines in XZ and YZ planes may also have bugs. Will report to GMT later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already reported to upstream GenericMappingTools/gmt#4387 and GenericMappingTools/gmt#4388. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah yes, forgot about So for now, I think we can just use The wall frames look good though, too bad we need to wait for GMT 6.2.0! But good that we found two bugs to report to upstream GMT 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, Edit: Opened up #676 to complete documentation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, with #676 merged, I've updated the code to use pygmt/examples/gallery/plot/scatter3d.py Line 34 in 40f7120
In the future when we bump the minimum GMT version to 6.2.0 which would include the new feature at GenericMappingTools/gmt#4390, we can do the following:
which would produce a nice colorbar ;) |
||||
fig.plot3d( | ||||
x=df.petal_width, | ||||
y=df.sepal_length, | ||||
z=df.petal_length, | ||||
sizes=0.1 * df.sepal_width, # Vary each symbol size according to a data column | ||||
color=df.species.cat.codes.astype(int), # Points colored by categorical number code | ||||
cmap=True, # Use colormap created by makecpt | ||||
region=region, # (xmin, xmax, ymin, ymax, zmin, zmax) | ||||
frame=[ | ||||
"WsNeZ3", # z axis label positioned on 3rd corner | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about adding a title here? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Agree |
||||
'xafg+l"Petal Width"', | ||||
'yafg+l"Sepal Length"', | ||||
'zafg+l"Petal Length"', | ||||
], | ||||
style="uc", # 3D cUbe, with size in centimeter units | ||||
perspective=[315, 25], # Azimuth NorthWest (315°), at elevation 25° | ||||
zscale=1.5, # Vertical exaggeration factor | ||||
) | ||||
fig.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.
A little off-topic, but should we sort all the methods alphabetically?
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.
Maybe just for the
Figure.*
methods, but that's for a separate PR.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.
Yes.