I'm currently working on a project in Python and I need to plot some data in real time. I would like to make a GUI, thinking of using Tkinter library. I am using matplotlib for ploting.
The program has a for loop in main in which i call a function (lets call it A_func) that needs about 1 ms to 20 ms to preform (depends on curvefit problem). in every iteration of for loop (A_func calculation) i would like to "modify" my plot on GUI (I am ploting outputs of A_func)
In the code below i tried to simply present my code.
MAIN
# Some code
for ID in range(0, 3000):
[output_data1, output_data2, output_data3] = A_func(ID, input_data1, input_data2, input_data3)
# I would like to modify my plot (GUI)
# example: plot(output_data1, output_data2)
I'm a bit lost right now because I'm new to Python so any kind of help would be greatly appreciated
Matplotlib has some animation capabilities.
from matplotlib import pyplot as plt
import matplotlib.animation as animation
Look for examples in the doc's ( and with google )
Related
i'm getting started with scikit-geometry and am trying to reproduce some of the examples, but the plot function doesn't work as expected.
i'm working in VSCode and managing my environment with Anaconda on Windows 10.
i'm just reading through the samples in the notebook. the snippet runs, but no graphic is displayed.
import skgeom
from skgeom.draw import draw
from matplotlib import pyplot as plt
import math
a = skgeom.Point2(4, 5)
print('a:', a)
draw(a, color='purple')
the docs indicate that the draw function is built from the matplotlib plot function, but it doesn't support the .show() method, so i'm not really sure what i'm doing wrong.
suggestions?
I am making a Tkinter based application in python which tracks the movement of users and plot them on a graph.
now ploting the points on a graph is no biggie, but what i couldnt manage was to give the background image as a map
currently my progress for this particular feature is nothing but as follows.
import matplotlib.pylab as plt
a=[[],[]]
a[0]=[12.28384,12,23434]#100's of values extracted from some csv file
a[1]=[80.12332,80.13312]#consider a[0],a[1] as latitude,longitude respectively
plt.plot(a[0],a[1])
plt.show()
This answer explains how to embed a map in a Tkinter window and may help.
You could also look at this example that uses the GooMPy library to embed an interactive google map in a Tkinter window.
How can I use the mouse to explore a plot or image displayed in python?
I would like to:
use markers (add/remove/manipulate)
sample the data values (at plot/image/mesh)
continue evaluating code lines in the console
I am currently using matplotlib.pyplot for the display and mpldatacursor for interaction. is there better way?
my system (get stuck and crash too often) is: win7, python 2.7.6, matplotlib 1.4.2, mpldatacursor 0.5
i have a python interface using wxpython which allows the user to fill in a matrix (0/1) and then graphs it for them. The program creates a numpy matrix, then makes a networkx graph out of that matrix, and then uses matplotlib.pylab to display the graph.
numpy is a must, because the program also does other things like get the transitive, reflexive, and symmetric closures... as for networkx i can use something else if u recommend something else better for graphing matrices, and as for matplotlib, i hate it, please if u know of any other way to display a graph please advice.
matplotlib is the source of my problem, when the users clicks the graph button, my programs reads the matrix, makes a graphs and matplotlib displays it in a new window (by default). Now if the users goes back to the original window and graphs a different matrix without first closing the matplotlib window, the program crashes.
also the way the relationship "arrows" are drawn is, in my opinion, unattractive.
i need a better way to graph my matrix, or at the very least as a way to force close the myplotlib window, i tried plt.close() but that didnt work, the window would remain open, and both windows will say (Not Responding) and i have to end process.
this is the part of the code in question:
import numpy as np
import networkx as nx
import matplotlib.pylab as plt
...
...
...
def graph(values)
plt.close() #with or without this it does not work
matrix = np.matrix(values)
graph = nx.DiGraph(matrix)
nx.draw(graph)
plt.show()
return
It seems to me like your main complaint is in the way that wx handles the matplotlib windows. It is possible to embed the Matplotlib figure in your wx window. Here's an example:
http://wiki.scipy.org/Matplotlib_figure_in_a_wx_panel (updated)
It gets a bit complicated. Basically, you should copy the code and replace the "DemoPlotPanel.draw()" method. You'll need to modify your code to specify the axis to draw on. It's buried in the networkx documentation here:
http://networkx.lanl.gov/reference/drawing.html
I am just using an example of the Networkx documentation:
try:
import matplotlib.pyplot as plt
except:
raise
import networkx as nx
G=nx.star_graph(20)
pos=nx.spring_layout(G)
nx.draw(G,pos)
plt.show() # display
So your plt.close() statement at the start does not make sense, you should remove it.You should also calculate the coordinates for your nodes, the sentence pos=nx.spring_layout(G) does this. You call a specific layout algorithm and supply your graph G, you get a dictionary in return with for each node the x and y coordinates.
Have a close look at the examples at: http://networkx.lanl.gov/gallery.html
Here is a simple matlab script to read a csv file, and generate a plot (with which I can zoom in with the mouse as I desire). I would like to see an example of how this is done in python and mathplotlib.
data = csvread('foo.csv'); % read csv data into vector 'data'
figure; % create figure
plot (data, 'b'); % plot the data in blue
In general, the examples in mathplotlib tutorials I've seen will create a static graph, but it's not interactively "zoomable". Would any python expert care to share an equivalent?
Thanks
import matplotlib.pyplot as plt
import numpy as np
arr=np.genfromtxt('foo.csv',delimiter=',')
plt.plot(arr[:,0],arr[:,1],'b-')
plt.show()
on this data (foo.csv):
1,2
2,4
3,9
produces
When you setup the matplotlibrc, one of the key parameters you need to set is the backend. Which backend you choose depends on your OS and installation.
For any typical OS there should be a backend that allows you to pan and zoom the plot interactively. (GtkAgg works on Ubuntu). The buttons highlighted in red allow you to pan and zoom, respectively.
Since you're familiar with Matlab, I'd suggest using the pylab interface to matplotlib - it mostly mimics Matlab's plotting. As unutbu says, the zoomability of the plot is determined by the backend you use, a separate issue.
from pylab import *
data = genfromtxt("file.csv")
plot(data, 'b')