0

Is there a way to plot in an already open window in pandas. Suppose i have a dataframe of 10,000 items and only one column.

what I want to do is to keep plotting only 100 of those points at a time in that open plot window, like a streaming plot maybe.

So the outcome would be a open window that displays line plot of first 100 points then the next 100 points, i.e. 101 to 200 and so on....

i tried looking on the SO but could only find examples like : Real time matplotlib plot is not working while still in a loop I cannot make it play nice with df.plot() method....

3
  • 1
    are you feeding the Axes object to the plot method? Commented Nov 25, 2014 at 20:24
  • For future reference, you could try using matplotlib's animation options for this, e.g. here Commented Nov 25, 2014 at 21:49
  • I saw that but this method allows me to simply use the plotting functionality in pandas to create various plots that I need. So its easy to just work with dataframes... Commented Nov 25, 2014 at 22:15

2 Answers 2

3

put your plot in a loop and call clf() at the end of each loop. That will clear the matplotlib figure.

You may want to pursue treating this as an animation:

http://nbviewer.ipython.org/url/jakevdp.github.io/downloads/notebooks/AnimationEmbedding.ipynb

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, I firstly tried to make that work but couldn't use the .plot() method of pandas. This method is a little clumsy but allows me to plot using pandas functions. If you can create an example of animation with pandas, I would be grateful.
I tried for 10 min & also found it really hard. I'll try again today. I'll probably end up writing an SO question about it ;)
0

So I figured it out! Also, thanks for the help @JD Long. Here's a sample that works. Instead of using same dataframe values I am creating new columns on the fly and then plotting:

import time
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
pd.options.display.mpl_style = 'default'


df = pd.DataFrame({'a':[3,4,45,6,70,6],'b':[4,4,2,4,2,2]})

plt.axis([0, 50, 0, 100])
plt.ion()
plt.show()

for i in range(1,6):
    df.c = df.a + i
    df.b = df.b - i
    df.c.plot(title = str(i)+'th Iteration')
    df.b.plot(kind='bar', title = str(i)+'th Iteration')
    plt.draw()
    time.sleep(1)
    plt.pause(0.0001)
    plt.clf()
plt.close()

6 Comments

so you're using ipython notebook and NOT using inline plots then?
I have pasted this in a single cell of the notebook. and Yeah, I don't want to use inline plots because i feel its better to have a separate window where we can update the plots.
hmmm.. what OS are you running? On my Mac this method results in a big stack of plotting windows all stacked on top of each other
i highly recommend creating Figure and Axes instances (fig, ax = plt.subplots()) and using those explicitly.
@JD Long, ohh, I am running this on windows 8. I wonder if it doesn't work on mac , it might not run well on linux too. I will try Paul H's idea. I tried it earlier but made some mistake so couldn't make it work. I think that would solve the problem of many windows.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.