Making a chart bigger in size

2024/11/19 11:37:51

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?

Answer

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

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

See docs.

https://en.xdnf.cn/q/26443.html

Related Q&A

index of non NaN values in Pandas

From Pandas data frame, how to get index of non "NaN" values?My data frame isA b c 0 1 q1 1 1 2 NaN 3 2 3 q2 3 3 4 q1 NaN 4 5 q2 7And I want the…

How can I type-check variables in Python? [duplicate]

This question already has answers here:Whats the canonical way to check for type in Python?(16 answers)Closed 3 months ago.I have a Python function that takes a numeric argument that must be an intege…

Py_INCREF/DECREF: When

Is one correct in stating the following:If a Python object is created in a C function, but the function doesnt return it, no INCREF is needed, but a DECREF is. [false]If the function does return it, yo…

pop/remove items out of a python tuple

I am not sure if I can make myself clear but will try.I have a tuple in python which I go through as follows (see code below). While going through it, I maintain a counter (lets call it n) and pop item…

Difference between frompyfunc and vectorize in numpy

What is the difference between vectorize and frompyfunc in numpy?Both seem very similar. What is a typical use case for each of them?Edit: As JoshAdel indicates, the class vectorize seems to be built…

Jupyter notebook command does not work on Mac

I installed jupyter using pip on my macbook air. Upon trying to execute the command jupyter notebook, I get an error jupyter: notebook is not a Jupyter commandI used the --h option to get a listing of …

Recursively compare two directories to ensure they have the same files and subdirectories

From what I observe filecmp.dircmp is recursive, but inadequate for my needs, at least in py2. I want to compare two directories and all their contained files. Does this exist, or do I need to build …

Specific reasons to favor pip vs. conda when installing Python packages

I use miniconda as my default python installation. What is the current (2019) wisdom regarding when to install something with conda vs. pip?My usual behavior is to install everything with pip, and onl…

Insert a link inside a Pandas table

Id like to insert a link (to a web page) inside a Pandas table, so when it is displayed in an IPython notebook, I could press the link. I tried the following: In [1]: import pandas as pdIn [2]: df = pd…

TypeError: string indices must be integers while parsing JSON using Python?

I am confuse now why I am not able to parse this JSON string. Similar code works fine on other JSON string but not on this one - I am trying to parse JSON String and extract script from the JSON.Below …