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

AnchoredSizeBar does not respect FontProperties size setting. #2394

Closed
michaelaye opened this issue Sep 9, 2013 · 11 comments · Fixed by #2951
Closed

AnchoredSizeBar does not respect FontProperties size setting. #2394

michaelaye opened this issue Sep 9, 2013 · 11 comments · Fixed by #2951

Comments

@michaelaye
Copy link

The following code should produce very different font sizes in the AnchoredSizeBar text but it just shows the same size:

from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
from matplotlib.font_manager import FontProperties
fp = FontProperties()
fp.set_size('xx-large')
fig, ax = subplots(2)
ax[0].plot(arange(10))
asb = AnchoredSizeBar(ax[0].transData, 5, 'xx-large', loc=8, prop=fp)
ax[0].add_artist(asb)
ax[1].plot(arange(10))
fp.set_size('xx-small')
asb2 = AnchoredSizeBar(ax[1].transData, 5, 'xx-small', loc=8, prop=fp)
ax[1].add_artist(asb2)

This code produces the following output on my system:

figure_1

Env:
EPD 7.3 all recent official updates (= MPL 1.3.0),
IPython 1.0 with QT4 backend on MacOSX 10.8.4

@michaelaye
Copy link
Author

Setting the font size with integers directly seems to work, but set_weight('bold') is being ignored also.

@michaelaye
Copy link
Author

Trying to set the weight with absolute numbers (according to docs between 0...1000) does NOT work.

@pelson
Copy link
Member

pelson commented Sep 20, 2013

Thanks @michaelaye - looks like this could be a pretty easy fix. Fancy having a go?

@nickpyren
Copy link

Hey guys,

I was taking a look at this issue and I noticed that AnchoredSizeBar has another parameter in it's constructor called "fontproperties" and when I used that to set the font properties it seemed to work.

The "prop" parameter seems to be passed on to the parent constructor and inside of a comment in AnchoredOffsetbox it says that "prop : font property. This is only used as a reference for paddings." So that would explain why it wasn't actually adjusting the font size.

It seems a little redundant, so we could either keep it the way it is or remove "fontproperties" and just use the "prop" parameter.

Just an idea, let me know what you think!

@tacaswell tacaswell added this to the v1.4.0 milestone Feb 27, 2014
@tacaswell
Copy link
Member

@nickpyren At a minimum that should be made clear in the docsttring. Could you put together a PR updating them?

We are starting to triage for the 1.4.0 release, getting document changes in for 1.4 (and hence the next major re-rendering of the online docs) is do-able, re-factoring/changing the text api is not.

@tacaswell
Copy link
Member

@michaelaye Can you confirm that #2951 fixes your problem?

@michaelaye
Copy link
Author

Is it included in 1.3.1?

Edit: Ah, obviously it's not. I'm sorry, I don't have the time to install/compile github versions of MPL.

@tacaswell
Copy link
Member

in testing I also noticed an issue with re-using fp. The code does not make a copy of the FontProperty object internally so they are the same size because when they are rendered you are telling them to be the same size.

I think the following should work on 1.3.1 with no patching:

from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
from matplotlib.font_manager import FontProperties
fp = FontProperties()
fp.set_size('xx-large')
fig, ax = subplots(2)
ax[0].plot(arange(10))
asb = AnchoredSizeBar(ax[0].transData, 5, 'xx-large', loc=8, fontproperties=fp)
ax[0].add_artist(asb)
ax[1].plot(arange(10))
fp2 = FontProperties()
fp2.set_size('xx-small')
asb2 = AnchoredSizeBar(ax[1].transData, 5, 'xx-small', loc=8, fontproperties=fp2)
ax[1].add_artist(asb2)

@michaelaye
Copy link
Author

That throws for me:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-aa08d8ed9774> in <module>()
      5 fig, ax = subplots(2)
      6 ax[0].plot(arange(10))
----> 7 asb = AnchoredSizeBar(ax[0].transData, 5, 'xx-large', loc=8, fontproperties=fp)
      8 ax[0].add_artist(asb)
      9 ax[1].plot(arange(10))

/Users/maye/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/axes_grid1/anchored_artists.pyc in __init__(self, transform, size, label, loc, pad, borderpad, sep, prop, frameon, **kwargs)
     87                                    child=self._box,
     88                                    prop=prop,
---> 89                                    frameon=frameon, **kwargs)
     90 
     91 

/Users/maye/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/offsetbox.pyc in __init__(self, loc, pad, borderpad, child, prop, frameon, bbox_to_anchor, bbox_transform, **kwargs)
    908 
    909         """
--> 910         super(AnchoredOffsetbox, self).__init__(**kwargs)
    911 
    912         self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)

/Users/maye/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/offsetbox.pyc in __init__(self, *args, **kwargs)
    144     def __init__(self, *args, **kwargs):
    145 
--> 146         super(OffsetBox, self).__init__(*args, **kwargs)
    147 
    148         self._children = []

TypeError: __init__() got an unexpected keyword argument 'fontproperties'

@tacaswell
Copy link
Member

fontproperties was apparently added very recently (PR #2712 which I apparently saw go by, but have no memory of), sorry about that.

It looks like in 1.3.1 there is no way to change the font properties.

@tacaswell tacaswell modified the milestones: v1.4.x, v1.4.0 Jun 7, 2014
@tacaswell
Copy link
Member

Punted to 1.4.x

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

Successfully merging a pull request may close this issue.

4 participants