-
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 all 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,53 @@ | ||
""" | ||
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 <https://en.wikipedia.org/wiki/Iris_flower_data_set/>`__ | ||
can be visualized using a perspective 3-dimensional plot. The ``region`` | ||
argument has to include the :math:`x`, :math:`y`, :math:`z` axis limits in the | ||
form of (xmin, xmax, ymin, ymax, zmin, zmax), which can be done automatically | ||
using :meth:`pygmt.info`. To include the z-axis stick, set ``frame`` 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", color_model="+c", series=(0, 3, 1)) | ||
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.