Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06141da

Browse files
authored
Merge pull request #20574 from dmatos2012/tricontourf_hatching/example
Add tricontourf hatching example
2 parents 5faa1bb + e87dc9b commit 06141da

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

examples/images_contours_and_fields/tricontour_demo.py

Lines 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)