Return a list of artists and labels suitable for passing through to `~.Axes.legend` which represent this ContourSet. The labels have the form "0 < x <= 1" stating the data ranges which the artists represent. Parameters ---------- variable_na
(self, variable_name='x', str_format=str)
| 838 | return state |
| 839 | |
| 840 | def legend_elements(self, variable_name='x', str_format=str): |
| 841 | """ |
| 842 | Return a list of artists and labels suitable for passing through |
| 843 | to `~.Axes.legend` which represent this ContourSet. |
| 844 | |
| 845 | The labels have the form "0 < x <= 1" stating the data ranges which |
| 846 | the artists represent. |
| 847 | |
| 848 | Parameters |
| 849 | ---------- |
| 850 | variable_name : str |
| 851 | The string used inside the inequality used on the labels. |
| 852 | str_format : function: float -> str |
| 853 | Function used to format the numbers in the labels. |
| 854 | |
| 855 | Returns |
| 856 | ------- |
| 857 | artists : list[`.Artist`] |
| 858 | A list of the artists. |
| 859 | labels : list[str] |
| 860 | A list of the labels. |
| 861 | """ |
| 862 | artists = [] |
| 863 | labels = [] |
| 864 | |
| 865 | if self.filled: |
| 866 | lowers, uppers = self._get_lowers_and_uppers() |
| 867 | n_levels = len(self._paths) |
| 868 | for idx in range(n_levels): |
| 869 | artists.append(mpatches.Rectangle( |
| 870 | (0, 0), 1, 1, |
| 871 | facecolor=self.get_facecolor()[idx], |
| 872 | hatch=self.hatches[idx % len(self.hatches)], |
| 873 | )) |
| 874 | lower = str_format(lowers[idx]) |
| 875 | upper = str_format(uppers[idx]) |
| 876 | if idx == 0 and self.extend in ('min', 'both'): |
| 877 | labels.append(fr'${variable_name} \leq {lower}s$') |
| 878 | elif idx == n_levels - 1 and self.extend in ('max', 'both'): |
| 879 | labels.append(fr'${variable_name} > {upper}s$') |
| 880 | else: |
| 881 | labels.append(fr'${lower} < {variable_name} \leq {upper}$') |
| 882 | else: |
| 883 | for idx, level in enumerate(self.levels): |
| 884 | artists.append(Line2D( |
| 885 | [], [], |
| 886 | color=self.get_edgecolor()[idx], |
| 887 | linewidth=self.get_linewidths()[idx], |
| 888 | linestyle=self.get_linestyles()[idx], |
| 889 | )) |
| 890 | labels.append(fr'${variable_name} = {str_format(level)}$') |
| 891 | |
| 892 | return artists, labels |
| 893 | |
| 894 | def _process_args(self, *args, **kwargs): |
| 895 | """ |