Code Monkey home page Code Monkey logo

Comments (7)

jankatins avatar jankatins commented on August 17, 2024 1

Right now you could do this (all code without testing it ...):

from ggplot import * # sets the rcParam for figsize to a default
import matplotlib as mpl
mpl.rcParams["figure.figsize"] = "11, 8" # or  whatever you want
print( ggplot(...)  +...) 

Be aware that every usage of theme_gray() or theme_bw() will overwrite the mpl.rcparams again, so if you want to use these themes explicitly, you need to do it like this:

from ggplot  import *
theme_bw() # sets the default  to the bw settings
import matplotlib as mpl
mpl.rcParams["figure.figsize"] = "11, 8"
print( ggplot(...)  +...) # don't use any theme here!

Note that this hack is changed in the "Theme as contextmanager" PR #75, so if that's merged you could do this:

from ggplot  import *
mpl.rcParams["figure.figsize"] = "11, 8"
print( ggplot(...)  + theme_matplotlib(rc={"figure.figsize": "11, 8"}, matplotlib_defaults=False)

There is also a ggsave(), but right now this doesn't take a size parameter (I opened #96 for this)

from ggpy.

eduardflorinescu avatar eduardflorinescu commented on August 17, 2024

I tryed the first code example and it works. Thanks

from ggpy.

glamp avatar glamp commented on August 17, 2024

ggsave should now handle this

from ggpy.

shashispace avatar shashispace commented on August 17, 2024

in 0.5.8, theme is lost when you change size... is there a way to keep both theme and size?

Here's example code:

import pandas as pd
import numpy as np
import matplotlib as mpl
%matplotlib inline

from ggplot import *
theme_bw()

mpl.rcParams['figure.figsize'] = "15.0, 10.0"
gsize = theme_matplotlib(rc={"figure.figsize": "15, 10"}, matplotlib_defaults=False)

df = pd.DataFrame(np.random.randn(100,2),columns=['x','y'])
ggplot(df,aes('x','y')) + geom_line() + gsize

from ggpy.

Vageshwari avatar Vageshwari commented on August 17, 2024

When I print to a file , the size does not change. It remains same as original. Any way to control it?

from ggpy.

DSLituiev avatar DSLituiev commented on August 17, 2024

I was able to control the size of the figure by setting theme(plot_margin=...):

ggplot(df,aes('x','y')) + geom_line() + theme(plot_margin = dict(right = 15, top=10))

How about implementing an alternative plot_margin as tuple of two (width, height) ?

from ggpy.

grauscher avatar grauscher commented on August 17, 2024

Another solution, if you don't want to alter matplotlib's configuration:

from ggplot import *
from matplotlib import pyplot as plt

p = (ggplot(diamonds,
          aes(x='x', y='y', color='cut', fill='cut')) +
     geom_point() +
     facet_wrap(x='cut'))

# This command "renders" the figure and creates the attribute `fig` on the p object
p.make()

# Then you can alter its properties
p.fig.set_size_inches(15, 5, forward=True)
p.fig.set_dpi(100)
p.fig

# And display the final figure
plt.show()

from ggpy.

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.