diff --git a/plots.py b/plots.py index a8d19a0..29e2180 100644 --- a/plots.py +++ b/plots.py @@ -253,7 +253,7 @@ class QualtricsPlotsMixin: return chart.properties(title=title_config) - def _save_plot(self, chart: alt.Chart, title: str, filename: str | None = None) -> alt.Chart: + def _save_plot(self, chart: alt.Chart, title: str, filename: str | None = None, skip_footnote: bool = False) -> alt.Chart: """Save chart to PNG file if fig_save_dir is set. Args: @@ -261,11 +261,14 @@ class QualtricsPlotsMixin: title: Chart title (used for filename if filename not provided) filename: Optional explicit filename (without extension). If provided, this is used instead of deriving from title. + skip_footnote: If True, skip adding filter footnote (use when footnote + was already added to a sub-chart before vconcat). Returns the (potentially modified) chart with filter footnote added. """ # Add filter footnote - returns combined chart if filters active - chart = self._add_filter_footnote(chart) + if not skip_footnote: + chart = self._add_filter_footnote(chart) if hasattr(self, 'fig_save_dir') and self.fig_save_dir: path = Path(self.fig_save_dir) @@ -1382,11 +1385,14 @@ class QualtricsPlotsMixin: height=height or 350 ) + # Add filter footnote to main chart before combining with legend + main_chart = self._add_filter_footnote(main_chart) + # Add custom legend below the chart legend = self._create_gender_correlation_legend() chart = alt.vconcat(main_chart, legend, spacing=10).resolve_scale(color='independent') - chart = self._save_plot(chart, title, filename=filename) + chart = self._save_plot(chart, title, filename=filename, skip_footnote=True) return chart def plot_speaking_style_ranking_correlation_by_gender( @@ -1480,11 +1486,14 @@ class QualtricsPlotsMixin: height=height or 350 ) + # Add filter footnote to main chart before combining with legend + main_chart = self._add_filter_footnote(main_chart) + # Add custom legend below the chart legend = self._create_gender_correlation_legend() chart = alt.vconcat(main_chart, legend, spacing=10).resolve_scale(color='independent') - chart = self._save_plot(chart, title, filename=filename) + chart = self._save_plot(chart, title, filename=filename, skip_footnote=True) return chart def plot_speaking_style_color_correlation( @@ -1629,11 +1638,14 @@ class QualtricsPlotsMixin: height=height or 350 ) + # Add filter footnote to main chart before combining with legend + main_chart = self._add_filter_footnote(main_chart) + # Add custom legend below the chart legend = self._create_gender_correlation_legend() chart = alt.vconcat(main_chart, legend, spacing=10).resolve_scale(color='independent') - chart = self._save_plot(chart, title, filename=filename) + chart = self._save_plot(chart, title, filename=filename, skip_footnote=True) return chart def plot_demographic_distribution(