Coder Social home page Coder Social logo

Comments (1)

has2k1 avatar has2k1 commented on August 20, 2024

This is an case that we can't really fix and it should not be a bug. facet_wrap does not accept a column name, it accepts a valid python expression.

For example

import numpy as np, pandas as pd, plotnine as p9
rng = np.random.default_rng(seed=123)
df = pd.DataFrame({
    "x1": rng.standard_normal(size=100),
    "x2": rng.standard_normal(size=100),
    "with space": rng.choice(['a', 'b', 'c'], size=100, replace=True),
    "nospace": rng.choice(['a', 'b', 'c'], size=100, replace=True)
})

def double(series):
    return series * 2

(
    p9.ggplot(
        df,
        p9.aes(x="x1", y="x2")
    )
    + p9.geom_point()
    + p9.geom_abline(slope=1, intercept=0)
    + p9.facet_wrap("double(nospace)")

    # These are also valid 
    # + p9.facet_wrap("double( nospace )")  
    # + p9.facet_wrap("nospace.str.upper()")

    # This is invalid for all cases
    #+ p9.facet_wrap("double(with space)") 
)

facet_wrap_expression

It will succeed if change any of the following:

I remove the call to geom_abline.
I remove the call to facet_wrap.

These work just by chance because the column is not evaluated as code for any of those cases. But as you build more complicated plots it becomes inevitable. Ideally all column names should be valid python symbol names.

from plotnine.

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.