Skip to content Skip to sidebar Skip to footer

Too Many Legend With Array Column Data In Matplotlib

I try to plot simple rotation matrix result with list data. but My figure with result array have so many index as screen dump image. and the second plot is not exact with my attrib

Solution 1:

The issue is that you are trying to plot the two rows of result_a as if they were 1-dimensional np.ndarrays, when in fact they are np.matrix which are always 2-dimensional. See for yourself:

>>> result_a[0].shape
(1, 19)

To remedy this, you need to convert your vectors result_a[0], result_a[1] to arrays. Simple ways can be found in this answer. For example,

rx = result_a[0].A1
ry = result_a[1].A1
# alternatively, the more compact
# rx, ry = np.array(result_a)
plt.plot(rx, ry, 'r*-', label='rotated')

yields the following (with plt.legend(); plt.show()):

enter image description here


Post a Comment for "Too Many Legend With Array Column Data In Matplotlib"