Skip to content

Commit c6d2c63

Browse files
Add labelling scheme and field subset example to plot templates
1 parent 73dd932 commit c6d2c63

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

docs/source/gallery/examples/plotting/templates.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@
116116
JensenPlot(linewidth=0.4, add_labels=True, figsize=(7, 7))
117117
plt.show()
118118
########################################################################################
119+
# Customization - Labelling Schemes and Field Subsets
120+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121+
# For most templates, you're able to customize which labels are applied to each field.
122+
# This includes swapping between the 'ID' and the 'name' (and for TAS, swapping between
123+
# intrusive and volcanic equivalents), as well as specifing that only fields with specific
124+
# IDs are added to the diagram. For example, here we add volcanic labels for a subset of
125+
# fields in a TAS diagram (in this case, the LeMaitre version):
126+
#
127+
ax = TAS(
128+
linewidth=0.5,
129+
add_labels=True,
130+
which_model="LeMaitre",
131+
which_labels="volcanic",
132+
which_ids=["Pc", "Ba", "Bs", "O1", "O2", "U1", "U2", "U3", "S1", "S2", "S3"],
133+
figsize=(10, 5),
134+
)
135+
ax.figure
136+
########################################################################################
119137
# References and other notes for diagram templates can be found within the docstrings
120138
# and within the pyrolite documentation:
121139
#

pyrolite/plot/templates/TAS.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ def TAS(
4646
-----------
4747
.. [#ref_1] Middlemost, E. A. K. (1994).
4848
Naming materials in the magma/igneous rock system.
49-
Earth-Science Reviews, 37(3), 215224.
49+
Earth-Science Reviews, 37(3), 215-224.
5050
doi: {Middlemost1994}
5151
5252
.. [#ref_2] Le Bas, M.J., Le Maitre, R.W., Woolley, A.R. (1992).
5353
The construction of the Total Alkali-Silica chemical
5454
classification of volcanic rocks.
55-
Mineralogy and Petrology 46, 122.
55+
Mineralogy and Petrology 46, 1-22.
5656
doi: {LeBas1992}
5757
5858
"""

pyrolite/util/classification.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,12 @@ def _add_polygons_to_axes(
246246
poly_config.pop("color", None)
247247

248248
use_keys = not which_labels.lower().startswith("name")
249+
250+
if not which_ids:
251+
which_ids = list(self.fields.keys())
252+
249253
for k, cfg in self.fields.items():
250-
if cfg["poly"] and ((k in which_ids) or (len(which_ids) == 0)):
254+
if cfg["poly"] and (k in which_ids):
251255
verts = self.transform(np.array(_read_poly(cfg["poly"]))) * rescale_by
252256
pg = matplotlib.patches.Polygon(
253257
verts,
@@ -322,6 +326,7 @@ def add_to_axes(
322326
ax : :class:`matplotlib.axes.Axes`
323327
"""
324328
ax = init_axes(ax=ax, projection=self.projection)
329+
325330
ax = self._add_polygons_to_axes(
326331
ax=ax,
327332
fill=fill,
@@ -466,9 +471,13 @@ def add_to_axes(
466471
if axes_scale is not None: # rescale polygons to fit ax
467472
if not np.isclose(self.default_scale, axes_scale):
468473
rescale_by = axes_scale / self.default_scale
474+
475+
if not which_ids:
476+
which_ids = list(self.fields.keys())
477+
469478
if add_labels:
470479
for k, cfg in self.fields.items():
471-
if cfg["poly"] and ((k in which_ids) or (len(which_ids) == 0)):
480+
if cfg["poly"] and (k in which_ids):
472481
if which_labels.lower().startswith("id"):
473482
label = k
474483
elif which_labels.lower().startswith(

0 commit comments

Comments
 (0)