You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would there be opposition to adding x, y, ha, va as rcparams? I would like aligning labels to the end of axes to be a style option.
Or really a shortcut for set_label(), i.e. align "left" : <x/y>=0, ha='left' and "left" : <x/y>=1, ha='right' and align could be a new rcparam?
Sure, set_xlabel() currently takes ha='right', x=1 which effectively aligns label to the right. I would like this to be an optional default i.e. rcparam, though that could quickly get bloated ha/x/y for xaxis/yaxis. So alternatively set_xlabel() could take a new kwarg align={"right"|"center"|"left"} which would be a shortcut for setting the right ha/x/y and then align could be a singular new rcparam.
The idea is to align the axis label left/center/right with respect to the axis.
(horizontal/vertical)align unfortunately has a fixed notion to align the text relative to a reference point. Therefore adding a parameter align may be a source of confusion.
The desired effect is a bit analogous to the parameter loc in Axes.set_title. However, the difference is, that there are actually 3 titles which may be used simultaneously, and loc selects which title to use. OTOH legend() actually uses loc to move the legend. So set_xlabel('the label', loc='left') may after all be the way to go even if we just have one Text object for the label.
I don't have an issue with loc instead of align such that set_xlabel('the label', loc='left') where 'left' means set_xlabel('the label', ha='right', x=1) and similarly with 'right'. I'm happy to take a crack at a PR if we can get a consensus on the API.
If x=1 is already the way to do this maybe we capture x and allow special string values for it. Ie x=“left”. It would also allow us to document that you can just pass x to set_xlabel, whivc I hadn’t realized before now.
@jklymak Unfortunately for set_ylabel() it's y not x. The goal here is to have a setup that will allow for an rcParam like axis.label.loc = 'right' that will align all x-label, y-label, cbar-label to the right.
I'm in favor of a new loc='left' instead of x='left'. On the downside, we have another parameter that interacts with x and horizontalalignment. But also x='left' would still interact with horizontalalignment. We cannot get around that completely. Then IMHO it is clearer to introduce a separate loc parameter as a high-level interface that manipulates the low-level interface (x/horizontalalignment).
There's also some layouting happening in the non-axis direction, which overrides any y parameter given to xlabel:
If we pull x to top level in xlabel, people will get aware of y, but that does not work for setting the vertical position, which we would have to doc as well. Also for that reason, I don't think we should use or advertise x.
Activity
jklymak commentedon Dec 5, 2019
Can you clarify your proposed API? I'm not even clear what method you want these to apply to...
andrzejnovak commentedon Dec 5, 2019
Sure,
set_xlabel()currently takesha='right', x=1which effectively aligns label to the right. I would like this to be an optional default i.e. rcparam, though that could quickly get bloated ha/x/y for xaxis/yaxis. So alternativelyset_xlabel()could take a new kwargalign={"right"|"center"|"left"}which would be a shortcut for setting the rightha/x/yand thenaligncould be a singular new rcparam.timhoffm commentedon Dec 7, 2019
The idea is to align the axis label left/center/right with respect to the axis.
(horizontal/vertical)alignunfortunately has a fixed notion to align the text relative to a reference point. Therefore adding a parameteralignmay be a source of confusion.The desired effect is a bit analogous to the parameter
locin Axes.set_title. However, the difference is, that there are actually 3 titles which may be used simultaneously, andlocselects which title to use. OTOHlegend()actually useslocto move the legend. Soset_xlabel('the label', loc='left')may after all be the way to go even if we just have oneTextobject for the label.andrzejnovak commentedon Dec 7, 2019
I don't have an issue with loc instead of align such that
set_xlabel('the label', loc='left')where 'left' meansset_xlabel('the label', ha='right', x=1)and similarly with 'right'. I'm happy to take a crack at a PR if we can get a consensus on the API.jklymak commentedon Dec 7, 2019
If x=1 is already the way to do this maybe we capture x and allow special string values for it. Ie x=“left”. It would also allow us to document that you can just pass x to set_xlabel, whivc I hadn’t realized before now.
andrzejnovak commentedon Dec 7, 2019
@jklymak Unfortunately for
set_ylabel()it's y not x. The goal here is to have a setup that will allow for an rcParam like axis.label.loc = 'right' that will align all x-label, y-label, cbar-label to the right.timhoffm commentedon Dec 8, 2019
Technically
x/yis documented via the Text properties in kwargs (https://matplotlib.org/devdocs/api/_as_gen/matplotlib.axes.Axes.set_xlabel.html).I'm in favor of a new
loc='left'instead ofx='left'. On the downside, we have another parameter that interacts withxandhorizontalalignment. But alsox='left'would still interact withhorizontalalignment. We cannot get around that completely. Then IMHO it is clearer to introduce a separatelocparameter as a high-level interface that manipulates the low-level interface (x/horizontalalignment).There's also some layouting happening in the non-axis direction, which overrides any
yparameter given toxlabel:If we pull
xto top level inxlabel, people will get aware ofy, but that does not work for setting the vertical position, which we would have to doc as well. Also for that reason, I don't think we should use or advertisex.andrzejnovak commentedon Dec 8, 2019
Could also babyproof it, i.e throw error if both
x/haandlocget usedanntzer commentedon Dec 8, 2019
I think @timhoffm's point is a good one in favor of
loc="left"and againstx="left".QuLogic commentedon Jul 23, 2020
This was added in #15974.