Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions examples/mplot3d/contour3d_3.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
"""
========================================
Projecting contour profiles onto a graph
========================================
=====================================
Project contour profiles onto a graph
=====================================

Demonstrates displaying a 3D surface while also projecting contour 'profiles'
onto the 'walls' of the graph.

See contourf3d_demo2 for the filled version.
See :doc:`contourf3d_2` for the filled version.
"""

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.cm import coolwarm as cmap
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's recommended nowadays to use the colormap registry instead of importing from matplotlib.cm:

cmap = plt.colormaps['coolwarm']

You could go even one step further and use the string contour(..., cmap='coolwarm'). Usually, that's the simplest way if you don't need the colormap object itself. Here however, you have the cmap(0) call. I'm tempted to resolve this to an explicit '#3b4cc0' and get rid of the colormap object completely, which IMHO makes the example simpler.

But I'll let you choose whether to go all-string or retrieve cmap from plt.colormaps.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that cmap(0) is bugging me too. I was considering '#3b4cc0' too, but it is too cryptic. Is there some named blue in the neighborhood?

https://matplotlib.org/stable/gallery/color/named_colors.html#css-colors

Since I am green blind, I would like to kindly ask you to please help me out here: If you agree, please suggest a named blue instead of '#3b4cc0'. Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

You can try 'mediumblue' which is slightly darker, or 'royalblue' which is a bit lighter.


ax = plt.figure().add_subplot(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)

# Plot the 3D surface
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
ax.plot_surface(X, Y, Z, edgecolor=cmap(0), lw=0.5, rstride=8, cstride=8,
alpha=0.3)

# Plot projections of the contours for each dimension. By choosing offsets
# that match the appropriate axes limits, the projected contours will sit on
# the 'walls' of the graph.
ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cmap)
ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cmap)
ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cmap)

ax.set(xlim=(-40, 40), ylim=(-40, 40), zlim=(-100, 100),
xlabel='X', ylabel='Y', zlabel='Z')
Expand Down
19 changes: 10 additions & 9 deletions examples/mplot3d/contourf3d_2.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
"""
======================================
Projecting filled contour onto a graph
======================================
===================================
Project filled contour onto a graph
===================================

Demonstrates displaying a 3D surface while also projecting filled contour
'profiles' onto the 'walls' of the graph.

See contour3d_demo2 for the unfilled version.
See :doc:`contour3d_3` for the unfilled version.
"""

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.cm import coolwarm as cmap
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.


ax = plt.figure().add_subplot(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)

# Plot the 3D surface
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
ax.plot_surface(X, Y, Z, edgecolor=cmap(0), lw=0.5, rstride=8, cstride=8,
alpha=0.3)

# Plot projections of the contours for each dimension. By choosing offsets
# that match the appropriate axes limits, the projected contours will sit on
# the 'walls' of the graph
ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)
ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cmap)
ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cmap)
ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cmap)

ax.set(xlim=(-40, 40), ylim=(-40, 40), zlim=(-100, 100),
xlabel='X', ylabel='Y', zlabel='Z')
Expand Down