I am using Python 2.7.9 with matplotlib to display live data taken from a microcontroller in a FigureCanvasTKAgg. The figure itself must always display the last 100 points and resize the Y axis to display and 'snug fit' all points. X axis is updated as well to show the correct time stamp of each point.
This figure update involves redrawing all artists (as all of them change) at every figure update which is called using an after method every 100ms. I am using line.set_data(x,y) to update the actual data points and the required methods for updating the Y and X axes limits, followed by canvas.draw(). This works OK, at almost 5fps(the drawing itself takes ~100ms).
My question is: is there a faster way of doing this? From what I understand the draw method redraws the whole canvas including the subplots. Is there a way to update only the lines displayed and the splines and hence increase the fps?
I tried implementing a solution using ax.draw_artist(lines) and the rest, however this adds new artists and do not delete the previous ones.
Related
I am using Python for processing large datasets.
Each part of the data in the dataset is processed step by step in a cycle.
I need to add some visualization during processing.
Now I do plotting using matplotlib for current portion of data. For each step of the cycle I am executing function plot which plots new figure for each step..
The problem is I have a lot of data and plots... E.g. 1000000 plots, and if I will output it in Jupyter it just crashes. I want to use one figure and update data on it through a cycle and show it to see processing?
I want to create a ONE plot but the data on that figure will be changed on each step of processing - for current portion of data.
How to do that - to see that image during processing (e.g. using jupyter notebook)?
(So running through a cycle in one cell will show only one figure with one plot but the scatter on that plot will change cycle by cycle updating the existing figure)
something like:
update_plot(plot_name: str, datax: np.array, datay: np.array)
that will CHANGE the existing plot (important - I need to see it on the screen on each step - to understand that there is progress and it works correctly) It's like animation where each step - is a frame that needs to be changed. E.g. I am adding a special point on a plot for each step.
I am solving the Cahn hilliard equation, and it's already working. If i plot the figures at different iterations I obtain the correct result at the end. However, I need to show the change in concentration over the course of time in a video and not in multiple plots. I have tried using FuncAnimation but I can't figure out how to do it. I can't create a function that includes the frames. My concentration matrix is already updating after each iteration so how can I just tell the code to plot every update on the video?
I'm trying to animate a Matplotlib quiver. On every step amount of points, which are shown, is changing. This fact ruins the 'xy' scale, and I get errors 'Operands with different shapes cannot be broadcast together', where one shape belongs to x array in the first frame, and the other to current. When I change scale to 'inches' everything works fine.
So my question is: can I modify quiver scale in animation, so that it could properly handle new amount of points?
Thanks for any help.
I’ve been working on bokeh plots and I’m trying to plot a line graph taking values from a database. But the plot kind of traces back to the initial point and I don’t want that. I want a plot which starts at one point and stops at a certain point (and circle back). I’ve tried plotting it on other tools like SQLite browser and Excel and the plot seems ok which means I must be doing something wrong with the bokeh stuff and that the data points itself are not in error.
I’ve attached the images for reference and the line of code doing the line plot. Is there something I’ve missed?
>>> image = fig.line(“x”, “y”, color=color, source=something)
(Assume x and y are integer values and I’ve specified x and y ranges as DataRange1d(bounds=(0,None)))
Bokeh does not "auto-close" lines. You can see this is the case by looking at any number of examples in the docs and repository, but here is one in particular:
http://docs.bokeh.org/en/latest/docs/gallery/stocks.html
Bokeh's .line method will only "close up" if that is what is in the data (i.e., if the last point in the data is a repeat of the first point). I suggest you actually inspect the data values in source.data and I believe you will find this to be the case. Then the question is why is that the case and how to prevent it from doing that, but that is not really a Bokeh question.
https://github.com/enthought/chaco/blob/master/examples/demo/edit_line.py
My desired result is to have two plots side-by-side, the left is this edit_line.py plot, the right displays the sum of the y-values in edit_line.py and another array.
Right now I can look at self.component.index and self.component.value (x and y, respectively) from within PointDraggingTool. However, I need to be able to update the second plot based on updates in the first. How would I listen for changes in the first plot's traits and update the second by that amount?
I've figured it out -- I'll post a proper solution soon.
In summary, it required listening to updates of the first plot using on_trait_change(self.lineplot.value, self._handle_data_change, name="data_changed") and redrawing the second plot