question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I change figure size?

See original GitHub issue

If I try to set the figure size before, it creates the plot on figure 2, if I set the figure size on figure 2 to creates the plot on figure 3, etc

If this doesn’t work:

plt.figure(num=1, figsize=(16, 10))

How can I change the figure size of the ggplot chart?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jankatinscommented, Nov 5, 2013

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)

0reactions
grauschercommented, May 15, 2019

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()
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I change the size of figures drawn with Matplotlib?
The figsize tuple accepts inches, so if you want to set it in centimetres you have to divide them by 2.54. Have a...
Read more >
Change Figure Size in Matplotlib - Stack Abuse
First off, the easiest way to change the size of a figure is to use the figsize argument. You can use this argument...
Read more >
Change plot size in Matplotlib - Python - GeeksforGeeks
figsize() takes two parameters- width and height (in inches). By default the values for width and height are 6.4 and 4.8 respectively. Syntax:....
Read more >
How to Change Plot and Figure Size in Matplotlib - Datagy
One of the simplest and most expressive ways of changing the plot size in Matplotlib is to use the figsize= argument. As the...
Read more >
How To Change The Size Of Figures In Matplotlib
The first option you have is to call matplotlib.pyplot.figure that is used to create a new figure or activate an existing one. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found