Skip to content

Allow figsize to accept a single float that will scale the rcParam[figsize] #18244

Closed as not planned
@ianhi

Description

@ianhi

Problem

I often want to make a figure that is larger than what I have in my rcParams. However, I would also like to keep the same aspect ratio for this new figure, unfortunately this then requires that I do mental math 😞. For example if I want a figure be to be 1.5 times larger than the rcDefault size of [6.4, 4.8] then I will have to multiply in my head or add a few lines of code. Instead I normally just make a haphazard guess of two numbers of that I hope will result in a similar aspect ratio.

Proposed Solution

Modify the figsize argument to plt.figure to also accept a single float value. When given as (float, float) the original behavior will remain. When given as float then the figsize will be computed as a multiple of the rcParam figsize. Like so:

from collections import Iterable
def figure(figsize=1,*args,**kwargs):
    if not isinstance(figsize, Iterable):
        figsize = [figsize*x for x in rcParams['figure.figsize']]
    return plt.figure(figsize=figsize,*args,**kwargs)

Additional context and prior art

This is somewhat redundant with the dpi argument, but I think the proposed solution is more intuitive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions