Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Issues with non-numeric font sizes like "small" #129

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

Closed
NMC-DAVE opened this issue Mar 8, 2020 · 2 comments
Closed

Issues with non-numeric font sizes like "small" #129

NMC-DAVE opened this issue Mar 8, 2020 · 2 comments
Labels

Comments

@NMC-DAVE
Copy link

NMC-DAVE commented Mar 8, 2020

Hi:
I want to use the matplotlib style to pyplot, like:

import numpy as np
import matplotlib.pyplot as plt
import proplot as plot

state = np.random.RandomState(51423)
data = 2*(state.rand(100, 5) - 0.5).cumsum(axis=0)

# Simple plot
with plt.style.context('ggplot'):
    f, axs = plot.subplots(ncols=1, figsize=(10, 8))
    axs[0].plot(data, lw=2)
    axs[0].format(xticks=20, xtickminor=False)
    axs.format(
        suptitle='Simple subplot grid', title='Title',
        xlabel='x axis', ylabel='y axis'
    )

But I get the error:


TypeError Traceback (most recent call last)
in
4 # Simple plot
5 with plt.style.context('ggplot'):
----> 6 f, axs = plot.subplots(ncols=1, figsize=(10, 8))
7 axs[0].plot(data, lw=2)
8 axs[0].format(xticks=20, xtickminor=False)

~/anaconda3/lib/python3.7/site-packages/proplot/subplots.py in subplots(array, ncols, nrows, ref, order, aspect, figsize, width, height, journal, axwidth, axheight, hspace, wspace, space, hratios, wratios, width_ratios, height_ratios, left, bottom, right, top, basemap, proj, projection, proj_kw, projection_kw, **kwargs)
2372 sharex = _notNone(kwargs.get('sharex', None), share, rc['share'])
2373 sharey = _notNone(kwargs.get('sharey', None), share, rc['share'])
-> 2374 left = _notNone(left, _get_space('left'))
2375 right = _notNone(right, _get_space('right'))
2376 bottom = _notNone(bottom, _get_space('bottom'))

~/anaconda3/lib/python3.7/site-packages/proplot/subplots.py in _get_space(key, share, pad)
575 space = units(_notNone(pad, rc['subplots.pad'])) + (
576 rc['ytick.major.size'] + rc['ytick.labelsize']
--> 577 + rc['ytick.major.pad'] + rc['axes.labelsize']) / 72
578 elif key == 'right':
579 space = units(_notNone(pad, rc['subplots.pad']))

TypeError: unsupported operand type(s) for +: 'float' and 'str'

So, why? Thanks very much!

Dave

@lukelbd lukelbd added the bug label Mar 11, 2020
@lukelbd
Copy link
Collaborator

lukelbd commented Mar 11, 2020

Proplot expected rc['axes.labelsize'] to be a font size in points, but evidently this particular style specified the font size with a string like 'small' or 'large'.

This will be quite simple to fix; will try to get to it soon, and release a new version when it's done.

@lukelbd lukelbd changed the title Can not use the plot sytle Issues with non-numeric font sizes like "small" May 9, 2020
@lukelbd
Copy link
Collaborator

lukelbd commented May 9, 2020

This is fixed in the master branch (will release a new version soon). I've also added stylesheet support so rather than using style.context, you can use proplot's own context manager to turn on the 'ggplot' stylesheet as follows:

import proplot as plot
with plot.rc.context(style='ggplot'):
    ...  # do stuff

See the full discussion in #143.

@lukelbd lukelbd closed this as completed May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants