Git Product home page Git Product logo

Comments (8)

olgabot avatar olgabot commented on May 10, 2024

What about an sns.get_current_axes_style() function? There may be certain subplots that could be one style, and others another style. Or is this a more "Pythonic" route with with? I've only ever use with for opening files.

from seaborn.

mwaskom avatar mwaskom commented on May 10, 2024

Yes, I think using a context manager is a lot cleaner.

What this avoids is any kind of global variable naming the seaborn style. All the __enter__ method will do is copy the current rcParams and set them to something else, then the __exit__ method will just set the original rcParams back to what they were at the start of the block. This will respect any changes to the rcParams that have been made independently of seaborn.

Because of the way matplotlib works, (I think) only the code that creates the axis object needs to be inside the style context; after that, the axis knows about all the parameters that are going to control how it looks.

from seaborn.

mwaskom avatar mwaskom commented on May 10, 2024

Also I think it's preferable to have themes defined by a dictionary of rc parameters, with the names (nogrid, darkgrid, etc.) serving as aliases for those parameters.

from seaborn.

phobson avatar phobson commented on May 10, 2024

I think axes_style should also take keyword arguments that override any
rc values it's messing with/complement the changes.

How would you feel about similar functionality in sns.set(...)?

from seaborn.

mwaskom avatar mwaskom commented on May 10, 2024

How would you feel about similar functionality in sns.set(...)?

Ambivalent. set() feels like it's a little overloaded currently, but I'm going to reevaluate once I straighten out the set_* functions to work more cleanly.

Also it's since occurred to me that because of how the mpl parameters are named (i.e. the presence of periods) you can pass them as kwargs. So this will end up having to be a single argument taking a dict, I think.

from seaborn.

phobson avatar phobson commented on May 10, 2024

I see. Just to be clear, we're both talking about something a simple as this, right?

def set(context="notebook", style="darkgrid", palette="deep", font="Arial",
        gridweight=None, customparams={}):
    """Set new RC params in one step."""
    set_axes_style(style, context, font=font, gridweight=gridweight)
    set_color_palette(palette)
    mpl.rcParams.update(customparams)

Which will enable something like this: http://nbviewer.ipython.org/gist/phobson/9394948

from seaborn.

mwaskom avatar mwaskom commented on May 10, 2024

What is this, base R graphics? :)

Yeah, I don't have a big problem with that, I just want to leave set alone until the underlying set_* functions have a clear definition. One thing that is confusing about matplotlib is that there are like 15 different ways to set rc parameters, which is very un-pythonic. I am not sure I want to add 4 different ways (or whatever) of doing it in seaborn too. But, once the dust clears, this approach will probably seem reasonable.

from seaborn.

phobson avatar phobson commented on May 10, 2024

With you 100% on that. Just wanted to make sure we were on the same page :)

from seaborn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.