Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'QuadContourSet' object has no attribute 'collections' #121

Open
JaimeRZP opened this issue Feb 21, 2025 · 2 comments
Open

Comments

@JaimeRZP
Copy link

Dear team I think triangle_plot breaks in certain instances when using matplotlib 3.10

Code :

g = plots.getSubplotPlotter(subplot_size=2.5)
g.settings.axes_fontsize = 15
g.settings.legend_fontsize = 15
g.settings.axes_labelsize = 15
g.triangle_plot([samples_3x2_nuisance_nomarg,
                 samples_3x2_nuisance_wzdz_num,
                 samples_3x2_nuisance_wzdz_ana,
                 ],
                 ['Ωm', 'σ8', 'S8'],
                 upper_roots = [samples_3x2_nuisance_nomarg,
                                samples_3x2_nuisance_dz_num,
                                samples_3x2_nuisance_dz_ana,
                                ],
                 upper_kwargs = {'contour_colors':['black', 'C4', 'C2'],
                                'contour_ls': ['--', '-', '-'], 
                                    'filled': [False, True, True],
                                    'contour_lws':4}, 
                line_args=[{'color':'black'},
                           {'color':'C10'},
                           {'color':'C3'}], 
                colors=["black", 'C10', 'C3'],
                param_limits={'Ωm':(0.2, 0.4), 'σ8':(0.65, 0.9), 'S8':(0.67, 0.8)},
                filled=[False, True, True],
                contour_ls=['--', '-', '-'], 
                contour_lws=4,
                legend_ncol=1,
                 markers=prat_markers)
g.export("./paper_plots/triangle_1.pdf")

Error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[23], line 5
      3 g.settings.legend_fontsize = 15
      4 g.settings.axes_labelsize = 15
----> 5 g.triangle_plot([#samples_3x2_nuisance_nomarg,
      6                  samples_3x2_nuisance_wzdz_num,
      7                  samples_3x2_nuisance_wzdz_ana,
      8                  ],
      9                  ['Ωm', 'σ8', 'S8'],
     10                  upper_roots = [samples_3x2_nuisance_nomarg,
     11                                 samples_3x2_nuisance_dz_num,
     12                                 samples_3x2_nuisance_dz_ana,
     13                                 ],
     14                  upper_kwargs = {'contour_colors':['black', 'C4', 'C2'],
     15                                 'contour_ls': ['--', '-', '-'], 
     16                                     'filled': [False, True, True],
     17                                     'contour_lws':4}, 
     18                 line_args=[{'color':'black'},
     19                            {'color':'C10'},
     20                            {'color':'C3'}], 
     21                 colors=["black", 'C10', 'C3'],
     22                 param_limits={'Ωm':(0.2, 0.4), 'σ8':(0.65, 0.9), 'S8':(0.67, 0.8)},
     23                 filled=[False, True, True],
     24                 contour_ls=['--', '-', '-'], 
     25                 contour_lws=4,
     26                 legend_ncol=1,
     27                  markers=prat_markers)
     28 g.export("./paper_plots/triangle_1.pdf")

File ~/anaconda3/envs/gitd/lib/python3.13/site-packages/getdist/plots.py:2573, in GetDistPlotter.triangle_plot(self, roots, params, legend_labels, plot_3d_with_param, filled, shaded, contour_args, contour_colors, contour_ls, contour_lws, line_args, label_order, legend_ncol, legend_loc, title_limit, upper_roots, upper_kwargs, upper_label_right, diag1d_kwargs, markers, marker_args, param_limits, **kwargs)
   2569     self.plot_3d(roots, pair + [col_param], color_bar=False, line_offset=1, add_legend_proxy=False,
   2570                  do_xlabel=i2 == plot_col - 1, do_ylabel=i == 0, contour_args=contour_args,
   2571                  no_label_no_numbers=self.settings.no_triangle_axis_labels, ax=ax, **kwargs)
   2572 else:
-> 2573     self.plot_2d(roots, param_pair=pair, do_xlabel=i2 == plot_col - 1, do_ylabel=i == 0,
   2574                  no_label_no_numbers=self.settings.no_triangle_axis_labels, shaded=shaded,
   2575                  add_legend_proxy=i == 0 and i2 == 1, contour_args=contour_args, ax=ax, **kwargs)
   2576 if marker is not None:
   2577     self._add_marker_list(marker, ax, marker_args)

File ~/anaconda3/envs/gitd/lib/python3.13/site-packages/getdist/plots.py:1736, in GetDistPlotter.plot_2d(self, roots, param1, param2, param_pair, shaded, add_legend_proxy, line_offset, proxy_root_exclude, ax, mask_function, **kwargs)
   1734 contour_args = self._make_contour_args(len(roots), **kwargs)
   1735 for i, root in enumerate(roots):
-> 1736     res = self.add_2d_contours(root, param_pair[0], param_pair[1], line_offset + i, of=len(roots), ax=ax,
   1737                                mask_function=mask_function,
   1738                                add_legend_proxy=add_legend_proxy and root not in proxy_root_exclude,
   1739                                **contour_args[i])
   1740     xbounds, ybounds = self._update_limits(res, xbounds, ybounds)
   1741 if xbounds is not None and 'lims' not in kwargs:

File ~/anaconda3/envs/gitd/lib/python3.13/site-packages/getdist/plots.py:1134, in GetDistPlotter.add_2d_contours(self, root, param1, param2, plotno, of, cols, contour_levels, add_legend_proxy, param_pair, density, alpha, ax, mask_function, **kwargs)
   1132 dashes = args.get('dashes')
   1133 if dashes:
-> 1134     for c in cs.collections:
   1135         c.set_dashes([(0, dashes)])
   1136 if proxy_ix >= 0:

AttributeError: 'QuadContourSet' object has no attribute 'collections'

The error disappears if I downgrade matplotliv to verison 3.9.4

@cmbant
Copy link
Owner

cmbant commented Feb 21, 2025

Does this work?


if dashes:
    cs.set_dashes([(0, dashes)] * len(cs.levels))

@cmbant
Copy link
Owner

cmbant commented Feb 21, 2025

I tried pushing this to master, let me know if it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants