I’m tempted to agree with you on just passing the x and y labels as the text objects they are in draw_text. However, the exporter would definitely have to be able to tell the renderer that the xlabel, ylabel, and title are ‘special’ in some way. 

I’m wondering if that could be accomplished with a call like this (for an example xlabel):

            self.renderer.draw_text(text=content, position=position,
                                    coordinates=coordinates,
                                    style=style, type=‘xlabel', mplobj=text)

The exporter will know what each text object is because it can access it via ax.xaxis.get_label(), ax.yaxis.get_label(), ax.get_title(). Then, it would just need to make sure that it doesn’t pass the title object twice (right, the title is the only child of the axes object that would also need to be passed as special? I think the xlabel and ylabel objects aren’t children of the axes object, but rather children the xaxis and yaxis, right?

I like this approach, it would make sense to me to separate the layout of the axes from the text objects it contains.

Cheers,

Andrew

On Feb 28, 2014, at 3:33 PM, Jake Vanderplas <notifications@github.com> wrote:

> In mplexporter/renderers/plotly/plotly_renderer.py:
> 
> > +            for child in children:
> > +                if isinstance(child, matplotlib.text.Text):
> > +                    if child.get_text() == layout['xaxis{}'.format(self.axis_ct)]['title']:
> > +                        titlefont = {
> > +                            'size': child.get_size()
> > +                        }
> > +                        layout['xaxis{}'.format(self.axis_ct)]['titlefont'] = titlefont
> > +        if layout['yaxis{}'.format(self.axis_ct)]['title'] not in [None, 'None', 'none', '']:
> > +            children = ax.yaxis.get_children()
> > +            for child in children:
> > +                if isinstance(child, matplotlib.text.Text):
> > +                    if child.get_text() == layout['yaxis{}'.format(self.axis_ct)]['title']:
> > +                        titlefont = {
> > +                            'size': child.get_size()
> > +                        }
> > +                        layout['yaxis{}'.format(self.axis_ct)]['titlefont'] = titlefont
> And I don't think passing the xlabel and ylabel objects is the right choice here... what I'd envisioned for this exporter is to pass sufficient data to render the plot, and for 99% of the cases, have no need to dig into the internals of matplotlib objects (which, as you've discovered, is not too fun). Perhaps finding a way to pass the label styles would be better.
> 
> Actually, the only reason I'm passing the xlabel and ylabel at all (as opposed to just calling draw_text() on the appropriate objects to begin with) is because Peter Wang told me that he wanted labels to be treated specially. Perhaps this is not worth it, and we should just call draw_text() on them instead...
> 
> —
> Reply to this email directly or view it on GitHub.
>