|
45 | 45 | ax1.tricontour(triang, z, colors='k') |
46 | 46 | ax1.set_title('Contour plot of Delaunay triangulation') |
47 | 47 |
|
| 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 | + |
48 | 83 | ############################################################################### |
49 | 84 | # You can specify your own triangulation rather than perform a Delaunay |
50 | 85 | # triangulation of the points, where each triangle is given by the indices of |
|
101 | 136 | # object if the same triangulation was to be used more than once to save |
102 | 137 | # duplicated calculations. |
103 | 138 |
|
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)') |
111 | 146 |
|
112 | 147 | plt.show() |
113 | 148 |
|
|
120 | 155 | # |
121 | 156 | # - `matplotlib.axes.Axes.tricontourf` / `matplotlib.pyplot.tricontourf` |
122 | 157 | # - `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