Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python pandas : pd.options.display.mpl_style = 'default' causes graph crash

Everything is in the title. My graph is displayed properly when I do not set this option at the beginning of my python script, otherwise it opens the window for the graph but closes it straightback and end the run.

I am using pandas 0.14.0 and matplotlib 1.3.0.

Anyone already saw this ? You can see my code below if needed.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

#pd.options.display.mpl_style = 'default'

df = pd.DataFrame(np.random.randn(1000, 4), index=pd.date_range('1/1/2000',periods=1000), columns=list('ABCD'))
df = df.cumsum()
df.plot(legend=False)

plt.show()
like image 243
Maxi Avatar asked Jul 21 '14 17:07

Maxi


People also ask

How do I change pandas options?

As described above, get_option() and set_option() are available from the pandas namespace. To change an option, call set_option('option regex', new_value) .

How do I expand the output display to see more rows of A Pandas DataFrame?

Call pandas. set_option("display. max_rows", max_rows, "display. max_columns", max_cols) with both max_rows and max_cols as None to set the maximum number of rows and columns to display to unlimited, allowing the full DataFrame to be displayed when printed.

How do I show more rows in a DataFrame?

The default value of max_rows is 10. If set to 'None' then it means all rows of the data frame. Set value of display. max_rows to None and pass it to set_option and this will display all rows from the data frame.

What function in the pandas library can display the maximum rows or columns in a table?

display. max_rows and display. max_columns sets the maximum number of rows and columns displayed when a frame is pretty-printed.


2 Answers

I was experiencing a similar error with Matplotlib v1.4. The solution I found is to use

matplotlib.style.use('ggplot')

rather than

pd.options.display.mpl_style = 'default'

See - https://pandas-docs.github.io/pandas-docs-travis/visualization.html

like image 200
johnml1135 Avatar answered Sep 22 '22 17:09

johnml1135


Use the following:

plt.show(block=True)

like image 36
rmalhotra Avatar answered Sep 20 '22 17:09

rmalhotra