Making a chart bigger in size

Question:

I’m trying to get a bigger chart. However, the figure method from matplotlib does not seem to be working properly.

I get a message, which is not an error:

<matplotlib.figure.Figure at 0xa25f7f0>

My code:

import pandas.io.data as web
import pandas as pd
import matplotlib.pyplot as plt

%matplotlib inline
...
plt.figure(figsize=(20,10))
df2['media']= df2['SPY']*.6 + df2['TLT']*.4
df2.plot()
plt.show()

What’s wrong with my code?

Asked By: vsoler

||

Answers:

You can skip the first plt.figure() and just use the argument figsize:

df2.plot(figsize=(20,10))

See docs.

Answered By: Stefan

Another way is to pass the current axes to DataFrame.plot():

plt.figure(figsize=(20,10))
df2.plot(ax=plt.gca());

or create a figure and axes and pass the relevant axes explicitly:

fig, axs = plt.subplots(figsize=(20,10))
df2.plot(ax=axs);

or plot each column one-by-one in a plt.plot() call:

plt.figure(figsize=(20,10))
plt.plot(df2.index, df2['SPY'], df2.index, df2['TLT']);
Answered By: cottontail
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.