holoviews icon indicating copy to clipboard operation
holoviews copied to clipboard

Matplotlib `backend_opts` string-based list indexing does not work on `ArtistList` objects

Open sztal opened this issue 11 months ago • 0 comments

As in the title. The documentation is somewhat ambiguous on this, but the example in the corresponding part of the documentation (here) suggests that the indexing should work on any sequence-like attribute on matplotlib objects. But this is not the case.

For some reason it is possible to index legend.get_texts()[0:1].fontsize but not axis.texts[0:2].size, even though the ArtistList at axis.texts is a perfectly fine sequence-like object.

I consider this a bug, because this feature is logically implied by the examples given in the docs and there seem to be no reason under the sun to allow for the first and prohibit the second.

I think that there is some too strict an instance check checking for being a subclass of list instead of a generic Sequence.

ALL software version info

holoviews=1.18.3 matplotlib=3.8.0

Description of expected behavior and the observed behavior

Mappings like "axis.texts.size": 24 should just work. Instead they fail with warnings like:

Encountered error: 'ArtistList' object has no attribute 'set_fontsize', or could not find 'set_fontsize' method on 'ArtistList' model. Ensure the custom option spec 'axis.texts[0:2].fontsize' you provided references a valid method on the specified model.

Complete, minimal, self-contained example code that reproduces the issue

# code goes here between backticks
import holoviews as hv
hv.extension("matplotlib")

plot = hv.Text(0, 1, "Text")
plot.opts(
    backend_opts={
        "axis.texts[:].size": 200
    }
)

Stack traceback and/or browser JavaScript console output

Screenshots or screencasts of the bug in action

  • [Yes] I may be interested in making a pull request to address this

sztal avatar Mar 20 '24 11:03 sztal