I am building a GUI in PySide where I have to keep redrawing pandas.DataFrame
objects.
I found out in this simple snippet of code that plotting the pandas DataFrame object df
takes much longer to plot than the numpy.array
object, despite the fact that the plots are nearly identical. This is too slow for my GUI. Why is this so much slower?
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
data = np.cumsum(np.random.randn(100, 10), axis=0)
df = pd.DataFrame(data)
df.plot() # Compare the speed of this line... (slow)
plt.plot(data) # to this line. (fast)
I like the way that the pandas.DataFrame
plots look, especially because in my real example my x-axis is datetime
data from pandas
. I do not know how to format a matplotlib.pyplot
x-axis to look good with datetime
data.
How do I speed up pandas.DataFrame
plotting?