The plot method expects multiple points in lists or arrays, and you're 
passing scalars for the x and y arguments. One thing you could do is 
extract the coordinates from all measurements into lists and pass them to 
plot. For example:

xlist = [m.x for m in processedMeasurements]
ylist = [m.y for m in processedMeasurements]
p1.plot(xlist, ylist, pen=None, symbol='o')

Is there a way to rewrite the exception message that could make it more 
clear?

By the way, you can plot a single point at a time by wrapping the 
coordinate values in lists, e.g. plot([0.], [1.]), but this approach won't 
scale well as each plot call generates a separate PlotDataItem.

On Friday, June 19, 2020 at 10:43:55 AM UTC-7, andrea gotelli wrote:
>
>  Hi,
>
>
> I have this problem where i need to plot elements that are stored into an 
> list containing a UDT. 
>
> the class is the following:
>
> class Measurement:
>         def __init__(self, time, mh_dist, color, x, y):
>             self.time = float(time)
>             self.mh_dist = float(mh_dist)
>             self.color = color
>             self.x = float( x )
>             self.y = float( y )
>
> The I create a list containing elements of this class. 
>
> processedMeasurements = []
>
> for topic, meas, t in bag.read_messages(topics=['/Measurements']):
>
>         if meas.accepted:
>
>             processedMeasurements.append( Measurement(  t.to_sec(),
>                                                         meas.distance,
>                                                         'b',
>                                                         
> meas.pose.position.x,
>                                                         
> meas.pose.position.y) )
>         else:
>             processedMeasurements.append( Measurement(  t.to_sec(),
>                                                         meas.distance,
>                                                         'r',
>                                                         
> meas.pose.position.x,
>                                                         
> meas.pose.position.y) )
>
> The only thing that is important to understan here is that I am saving 
> data readed from a file. Later I would like to plot this data. 
>
> For example, the measurements contains a x and y position. I would like to 
> plot this position for every element in the list processedMeasurements. 
>
> However, doing something like:
>
> for measurement in processedMeasurements:
>         p1.plot(measurement.x, measurement.y, pen=None, symbol='o')
>
> Gives me the following error:
>
> Traceback (most recent call last):
>   File "/home/agotelli/catkin_ws/src/Project1/plotting/scripts/plotting", 
> line 514, in <module>
>     p1.plot(measurement.x, measurement.y, pen=None, symbol='o')
>   File 
> "/usr/local/lib/python2.7/dist-packages/pyqtgraph/graphicsItems/PlotItem/PlotItem.py",
>  
> line 640, in plot
>     item = PlotDataItem(*args, **kargs)
>   File 
> "/usr/local/lib/python2.7/dist-packages/pyqtgraph/graphicsItems/PlotDataItem.py",
>  
> line 185, in __init__
>     self.setData(*args, **kargs)
>   File 
> "/usr/local/lib/python2.7/dist-packages/pyqtgraph/graphicsItems/PlotDataItem.py",
>  
> line 395, in setData
>     raise Exception('When passing two unnamed arguments, both must be a 
> list or array of values. (got %s, %s)' % (str(type(args[0])), 
> str(type(args[1]))))
> Exception: When passing two unnamed arguments, both must be a list or 
> array of values. (got <type 'float'>, <type 'float'>)
>
>
> Does anybody knows how to solve this problem??
>
> Thank you in advance. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/db3cf471-8c19-431c-8fe9-6e85bb907c8fo%40googlegroups.com.

Reply via email to