I have wrapped a C library in python using ctypes and called the DLLs. I then created a for-loop that prints out all of my data. Here is a small sample of the code that I have wrapped.
import ctypes
from ctypes import *
import matplotlib.pyplot as plt
class ParmData(Union):
_fields_ = [
('c', ctypes.POINTER(ctypes.c_ubyte)),
('f', ctypes.POINTER(ctypes.c_float))]
class SParm(Structure):
pass
SParm._fields_ = [
('data', ctypes.POINTER(ParmData)),
('time', ctypes.POINTER(ctypes.c_float))]
dll.readSParm.argtypes = (POINTER(SFile), c_char_p, c_double, c_double, c_double, POINTER(TTag), c_ushort,)
dll.readSParm.restype = POINTER(SParm)
g = dll.readSParm(SF, ParmName, startTime, stopTime, Null, None, convertType)
dll.freeSParm(g)
I want to create a simple graph with data points that are printed out from a for loop. This is what I have so far:
for i in range(0, 1032):
x = (g[0].time[i])
y = (g[0].data[0].f[i])
print(i, x, y)
This for-loop works perfectly and prints out all of the data into a neat list, but I need that list to be plotted into a simple graph. The return of the for-loop looks like this:
1028 -1.2241029739379883 1.7323481895261962e+19
1029 -0.22411400079727173 2.635080461412465e+23
1030 0.7759910225868225 1.7829588197038883e+19
1031 1.7759920358657837 1.8027558490491145e+28
Where the second column corresponds to the time value and the third column is the data values for that time.
I set x and y equal to pointers to objects that are contain all of the data.
I'm having a difficult time getting that data into a graph. idk what i'm doing wrong because in most of the matplotlib examples they just create random data and plot it. I need a way to get my data into the graph.
This doesn't work:
plt.plot(x, y)
plt.show()
It builds a graph, but it doesn't populate the data into the graph. This is what my graph looks like which is no good.
My question is this:
how can I get my data from a printed list of value pairs into a basic graph?
See Question&Answers more detail:
os