GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PYTHON CHARTS
  • matplotlib
  • seaborn
  • plotly
  • pandas
  • colors
  • COLORS
  • COLOR PALETTES
  • R CODER
  • R CHARTS
  • Contact
  • Español

This view

  • Original page
  • New address

GeezerVison is showing python-charts.com — Figure size and styles in pandas

Search for a graph

HOME PANDAS STYLES

Figure size and styles in pandas

As pandas charts are made with matplotlib, their size and their general appearance are controlled in the same way as in matplotlib: with figsize and with style sheets.

Figure size with figsize

The figsize argument sets the width and the height of the figure in inches.

Change the size of a pandas plot with figsize

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({"Solar": [5, 8, 12, 17, 23, 30, 38, 47, 55, 64, 72],
                   "Wind": [20, 23, 27, 30, 34, 37, 40, 44, 47, 50, 53],
                   "Hydro": [35, 34, 36, 33, 35, 34, 32, 33, 34, 33, 32]},
                  index = range(2015, 2026))

df.plot(figsize = (8, 3))
# plt.show()

Default size

To change the size of all the charts change figure.figsize in rcParams.

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = (8, 5)

Style sheets

Any matplotlib style sheet changes the appearance of pandas charts. Use plt.style.use to apply it to all the charts or plt.style.context to apply it only to one.

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({"Solar": [5, 8, 12, 17, 23, 30, 38, 47, 55, 64, 72],
                   "Wind": [20, 23, 27, 30, 34, 37, 40, 44, 47, 50, 53],
                   "Hydro": [35, 34, 36, 33, 35, 34, 32, 33, 34, 33, 32]},
                  index = range(2015, 2026))

with plt.style.context("ggplot"):
    df.plot(linewidth = 2)
    plt.show()

ggplot style in a pandas plot

Dark background

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({"Solar": [5, 8, 12, 17, 23, 30, 38, 47, 55, 64, 72],
                   "Wind": [20, 23, 27, 30, 34, 37, 40, 44, 47, 50, 53],
                   "Hydro": [35, 34, 36, 33, 35, 34, 32, 33, 34, 33, 32]},
                  index = range(2015, 2026))

with plt.style.context("dark_background"):
    df.plot.area()
    plt.show()

Dark background style in a pandas plot

Seaborn themes

sns.set_theme changes the default matplotlib parameters, so the seaborn themes are also applied to pandas charts.

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({"Solar": [5, 8, 12, 17, 23, 30, 38, 47, 55, 64, 72],
                   "Wind": [20, 23, 27, 30, 34, 37, 40, 44, 47, 50, 53],
                   "Hydro": [35, 34, 36, 33, 35, 34, 32, 33, 34, 33, 32]},
                  index = range(2015, 2026))
import seaborn as sns

sns.set_theme(style = "whitegrid")
df.plot.bar(stacked = True, rot = 45)
# plt.show()
sns.reset_orig()

Seaborn theme in a pandas plot

See the list of all the matplotlib style sheets and the seaborn themes, or how to change the figure size in matplotlib.

R CODER website
Data visualization

Data visualization

A practical introduction

Buy on Amazon
Storytelling with Data

Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon

See also

Subplots in pandas

Subplots in pandas

Legend in pandas

Legend in pandas

Titles and axis labels in pandas

Titles and axis labels in pandas

Colors in pandas

Colors in pandas

Axis customization in pandas

Axis customization in pandas

Plotting with pandas

Plotting with pandas

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.