Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e87dc9b

Browse filesBrowse files
committed
Add tricontourf hatching example
1 parent 20b13ff commit e87dc9b
Copy full SHA for e87dc9b

File tree

Expand file treeCollapse file tree

1 file changed

+45
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+45
-7
lines changed

‎examples/images_contours_and_fields/tricontour_demo.py

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/tricontour_demo.py
+45-7Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,41 @@
4545
ax1.tricontour(triang, z, colors='k')
4646
ax1.set_title('Contour plot of Delaunay triangulation')
4747

48+
49+
###############################################################################
50+
# You could also specify hatching patterns along with different cmaps.
51+
52+
fig2, ax2 = plt.subplots()
53+
ax2.set_aspect("equal")
54+
tcf = ax2.tricontourf(
55+
triang,
56+
z,
57+
hatches=["*", "-", "/", "//", "\\", None],
58+
cmap="cividis"
59+
)
60+
fig2.colorbar(tcf)
61+
ax2.tricontour(triang, z, linestyles="solid", colors="k", linewidths=2.0)
62+
ax2.set_title("Hatched Contour plot of Delaunay triangulation")
63+
64+
###############################################################################
65+
# You could also generate hatching patterns labeled with no color.
66+
67+
fig3, ax3 = plt.subplots()
68+
n_levels = 7
69+
tcf = ax3.tricontourf(
70+
triang,
71+
z,
72+
n_levels,
73+
colors="none",
74+
hatches=[".", "/", "\\", None, "\\\\", "*"],
75+
)
76+
ax3.tricontour(triang, z, n_levels, colors="black", linestyles="-")
77+
78+
79+
# create a legend for the contour set
80+
artists, labels = tcf.legend_elements(str_format="{:2.1f}".format)
81+
ax3.legend(artists, labels, handleheight=2, framealpha=1)
82+
4883
###############################################################################
4984
# You can specify your own triangulation rather than perform a Delaunay
5085
# triangulation of the points, where each triangle is given by the indices of
@@ -101,13 +136,13 @@
101136
# object if the same triangulation was to be used more than once to save
102137
# duplicated calculations.
103138

104-
fig2, ax2 = plt.subplots()
105-
ax2.set_aspect('equal')
106-
tcf = ax2.tricontourf(x, y, triangles, z)
107-
fig2.colorbar(tcf)
108-
ax2.set_title('Contour plot of user-specified triangulation')
109-
ax2.set_xlabel('Longitude (degrees)')
110-
ax2.set_ylabel('Latitude (degrees)')
139+
fig4, ax4 = plt.subplots()
140+
ax4.set_aspect('equal')
141+
tcf = ax4.tricontourf(x, y, triangles, z)
142+
fig4.colorbar(tcf)
143+
ax4.set_title('Contour plot of user-specified triangulation')
144+
ax4.set_xlabel('Longitude (degrees)')
145+
ax4.set_ylabel('Latitude (degrees)')
111146

112147
plt.show()
113148

@@ -120,3 +155,6 @@
120155
#
121156
# - `matplotlib.axes.Axes.tricontourf` / `matplotlib.pyplot.tricontourf`
122157
# - `matplotlib.tri.Triangulation`
158+
# - `matplotlib.figure.Figure.colorbar` / `matplotlib.pyplot.colorbar`
159+
# - `matplotlib.axes.Axes.legend` / `matplotlib.pyplot.legend`
160+
# - `matplotlib.contour.ContourSet.legend_elements`

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.