maidr 1.8.0__py3-none-any.whl → 1.8.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
maidr/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.8.0"
1
+ __version__ = "1.8.1"
2
2
 
3
3
  from .api import close, render, save_html, show, stacked
4
4
  from .core import Maidr
@@ -52,18 +52,73 @@ class GroupedBarPlot(
52
52
  [patch for container in plot for patch in container.patches]
53
53
  )
54
54
 
55
- for container in plot:
55
+ # Get hue categories from legend
56
+ hue_categories = self._extract_hue_categories_from_legend()
57
+
58
+ for i, container in enumerate(plot):
56
59
  if len(x_level) != len(container.patches):
57
60
  return None
58
61
  container_data = []
62
+
63
+ # Use hue category if available, otherwise fall back to container label
64
+ fill_value = hue_categories[i] if i < len(hue_categories) else container.get_label()
65
+
59
66
  for x, y in zip(x_level, container.patches):
60
67
  container_data.append(
61
68
  {
62
69
  MaidrKey.X.value: x,
63
- MaidrKey.FILL.value: container.get_label(),
70
+ MaidrKey.FILL.value: fill_value,
64
71
  MaidrKey.Y.value: float(y.get_height()),
65
72
  }
66
73
  )
67
74
  data.append(container_data)
68
75
 
69
76
  return data
77
+
78
+ def _extract_hue_categories_from_legend(self) -> list[str]:
79
+ """
80
+ Extract hue categories from the axes legend.
81
+
82
+ This method reads the legend text elements from the axes legend,
83
+ trims whitespace from each text, and returns a list of cleaned
84
+ category names. This is used to get the actual category names
85
+ instead of using the generic container labels like '_container0', '_container1'.
86
+
87
+ Parameters
88
+ ----------
89
+ None
90
+ This method uses the instance's axes object.
91
+
92
+ Returns
93
+ -------
94
+ list[str]
95
+ List of trimmed hue category names from the legend.
96
+ Returns empty list if no legend is found or if legend has no text elements.
97
+
98
+ Examples
99
+ --------
100
+ >>> # For a seaborn barplot with hue='category' and legend showing 'Below', 'Above'
101
+ >>> plot = GroupedBarPlot(ax, PlotType.DODGED)
102
+ >>> categories = plot._extract_hue_categories_from_legend()
103
+ >>> print(categories)
104
+ ['Below', 'Above']
105
+
106
+ >>> # If no legend exists
107
+ >>> categories = plot._extract_hue_categories_from_legend()
108
+ >>> print(categories)
109
+ []
110
+ """
111
+ legend = self.ax.get_legend()
112
+ if legend is None:
113
+ return []
114
+
115
+ # Get legend text elements
116
+ legend_texts = legend.get_texts()
117
+ if not legend_texts:
118
+ return []
119
+
120
+ # Extract text content from legend elements and trim whitespace
121
+ hue_categories = [text.get_text().strip() for text in legend_texts]
122
+
123
+ # Filter out empty strings and return
124
+ return [category for category in hue_categories if category]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maidr
3
- Version: 1.8.0
3
+ Version: 1.8.1
4
4
  Summary: Multimodal Access and Interactive Data Representations
5
5
  Project-URL: Homepage, https://xability.github.io/py-maidr
6
6
  Project-URL: Repository, https://github.com/xability/py-maidr
@@ -1,4 +1,4 @@
1
- maidr/__init__.py,sha256=WHwg8BcJQIcf4dsUFOdKS_frxDfuHewDEGnBBg9j3WE,415
1
+ maidr/__init__.py,sha256=KlhM_Qllqa69TYYU98Ba_yfOHROB9TYO3rIbVitC1D8,415
2
2
  maidr/api.py,sha256=od539V0CKcs15FEXQo0hX_hK_A0U3noHE54obdHcTqY,4138
3
3
  maidr/core/__init__.py,sha256=WgxLpSEYMc4k3OyEOf1shOxfEq0ASzppEIZYmE91ThQ,25
4
4
  maidr/core/context_manager.py,sha256=6cT7ZGOApSpC-SLD2XZWWU_H08i-nfv-JUlzXOtvWYw,3374
@@ -13,7 +13,7 @@ maidr/core/plot/__init__.py,sha256=xDIpRGM-4DfaSSL3nKcXrjdMecCHJ6en4K4nA_fPefQ,8
13
13
  maidr/core/plot/barplot.py,sha256=0hBgp__putezvxXc9G3qmaktmAzze3cN8pQMD9iqktE,2116
14
14
  maidr/core/plot/boxplot.py,sha256=i11GdNuz_c-hilmhydu3ah-bzyVdFoBkNvRi5lpMrrY,9946
15
15
  maidr/core/plot/candlestick.py,sha256=ofvlUwtzaaopvv6VjNDf1IZODbu1UkMHsi1zdvcG-Yo,10120
16
- maidr/core/plot/grouped_barplot.py,sha256=_zn4XMeEnSiDHtf6t4-z9ErBqg_CijhAS2CCtlHgYIQ,2077
16
+ maidr/core/plot/grouped_barplot.py,sha256=odZ52Pl22nb9cWKD3NGsZsyFDxXdBDAEcbOj66HKp9I,4063
17
17
  maidr/core/plot/heatmap.py,sha256=yMS-31tS2GW4peds9LtZesMxmmTV_YfqYO5M_t5KasQ,2521
18
18
  maidr/core/plot/histogram.py,sha256=QV5W-6ZJQQcZsrM91JJBX-ONktJzH7yg_et5_bBPfQQ,1525
19
19
  maidr/core/plot/lineplot.py,sha256=uoJpGkJB3IJSDJTwH6ECxLyXGdarsVQNULELp5NncWg,4522
@@ -52,7 +52,7 @@ maidr/util/mixin/extractor_mixin.py,sha256=j2Rv2vh_gqqcxLV1ka3xsPaPAfWsX94CtKIW2
52
52
  maidr/util/mixin/merger_mixin.py,sha256=V0qLw_6DUB7X6CQ3BCMpsCQX_ZuwAhoSTm_E4xAJFKM,712
53
53
  maidr/widget/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
54
  maidr/widget/shiny.py,sha256=wrrw2KAIpE_A6CNQGBtNHauR1DjenA_n47qlFXX9_rk,745
55
- maidr-1.8.0.dist-info/METADATA,sha256=JSCtmOqsD8Mka8aDihHcqHs4wJ9Yc4eBYV3by-pQSl0,3154
56
- maidr-1.8.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
57
- maidr-1.8.0.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
58
- maidr-1.8.0.dist-info/RECORD,,
55
+ maidr-1.8.1.dist-info/METADATA,sha256=oi8YKhP-r2l0NN9AnBTngZFG11lQK1jtSnRsWj8osjc,3154
56
+ maidr-1.8.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
57
+ maidr-1.8.1.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
58
+ maidr-1.8.1.dist-info/RECORD,,
File without changes