Skip to content

API: convert string fontsize to points immediately - #7007

Merged
QuLogic merged 9 commits into
matplotlib:v2.xfrom
tacaswell:api_set_font_size_at_creation_time
Dec 12, 2016
Merged

QuLogic merged 9 commits into
matplotlib:v2.xfrom
tacaswell:api_set_font_size_at_creation_time

Conversation

@tacaswell

Copy link
Copy Markdown
Member

This bakes into the text artist (via the FontProperties) the default
fontsize at the time of creation.

Possibly closes #7005

@tacaswell tacaswell added this to the 2.0 (style change major release) milestone Aug 30, 2016
@tacaswell

Copy link
Copy Markdown
Member Author

The upside of this is that this fixes one more class of thing that does not work with rc_context.

The down side is that, as implemented, you lose the nice string representation and it cuts against the request people have to re-style existing figures.

@tacaswell
tacaswell force-pushed the api_set_font_size_at_creation_time branch from dbf9c62 to 8d64fae Compare September 5, 2016 20:29
@tacaswell

Copy link
Copy Markdown
Member Author

If we do decide to do this, then this needs to be extended to cover the rest of the rcparams that the font properties keeps track of.

@NelleV

NelleV commented Oct 31, 2016

Copy link
Copy Markdown
Member

Any more thoughts on this?
That may be worth mentioning during our next meeting?

@tacaswell

Copy link
Copy Markdown
Member Author

I think the consensus is that this should be done for all of the font related rcparams to bring their behavior inline with the rest of the rcparams.

@tacaswell

Copy link
Copy Markdown
Member Author

@efiring @NelleV This is probably ready to review. Turns out the other properties I wanted to make sure we handled early were arleady handled early.

This may also fix one a usetex related bug (but I don't have enough time right now to track it donw).

@tacaswell
tacaswell force-pushed the api_set_font_size_at_creation_time branch from 082add4 to ae89d3e Compare December 4, 2016 20:14
Comment thread lib/matplotlib/text.py Outdated
if renderer.flipy():
y = canvash - y
clean_line, ismath = textobj.is_math_text(line)
clean_line, ismath = textobj.is_math_text(line, self.get_usetex())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matplotlib/text.py:785:80: E501 line too long (82 > 79 characters)

Comment thread lib/matplotlib/font_manager.py Outdated
@@ -673,11 +683,11 @@ def __init__(self,
_init = None # used only by copy()
):
self._family = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you forgotten to change this?

Comment thread lib/matplotlib/font_manager.py Outdated
if size is not None and size not in font_scalings:
try:
scale = font_scalings[size]
size = scale * FontManager.get_default_size()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to move this line into else block.

@tacaswell

Copy link
Copy Markdown
Member Author

It turns out that most of the rcParams were stashed at init time via #1329

@Kojoley Kojoley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_size and get_size_in_points are returning the same value now, is it ok?

Comment thread lib/matplotlib/font_manager.py Outdated
family = [six.text_type(family)]
elif (not is_string_like(family) and isinstance(family, Iterable)):
family = [six.text_type(f) for f in family]
family = _normalize_font_family(family)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but this could be just self._family = _normalize_font_family(family)

Comment thread lib/matplotlib/font_manager.py Outdated
def _normalize_font_family(family):
if is_string_like(family):
family = [six.text_type(family)]
elif (not is_string_like(family) and isinstance(family, Iterable)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not is_string_like(family) is always true here.

This bakes into the text artist (via the FontProperties) the default
fontsize at the time of creation.
@tacaswell
tacaswell force-pushed the api_set_font_size_at_creation_time branch from a14ec7d to 244cdb1 Compare December 12, 2016 20:12

@dopplershift dopplershift left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Seems much better to do this checking at __init__ time.

This appears to already be the case for all of these properties, but
remove the rcparams lookup from the get_* methods just to be sure.
`None` used to be a valid value for the style/slant and variant,
however in cc61700 the behavior was
changed to look up the defaults as set time (not get time) so there is
no reason to allow invalid values to be set to the internal state.
@tacaswell
tacaswell force-pushed the api_set_font_size_at_creation_time branch from 17d67fc to 5f4eead Compare December 12, 2016 20:59
@QuLogic
QuLogic merged commit f367003 into matplotlib:v2.x Dec 12, 2016
@tacaswell
tacaswell deleted the api_set_font_size_at_creation_time branch December 13, 2016 00:12
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

Successfully merging this pull request may close these issues.

6 participants