0

I have been trying to visualize a path saved in an array and to apply a color gradient along the line.

This is what I have so far:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

arr = np.array([[24.99487317, 55.466666  ,  0.        ],
       [24.99487367, 55.46666917,  1.        ],
       [24.99487217, 55.46667017,  2.        ],
       [24.99487183, 55.4666715 ,  3.        ],
       [24.99487133, 55.466673  ,  4.        ],
       [24.99487267, 55.466674  ,  5.        ]])

fig, ax = plt.subplots()
ax.plot(arr[:, 0], arr[:, 1], c=cm.hot(arr[:, 2]), linestyle='dashed')
plt.show()

I want that more recent points are evaluated higher (or more brighter on the 'hot' colormap). Somehow I always get the error:

ValueError: Invalid RGBA argument: array([[0.0416, 0.    , 0.    , 1.    ],
       [1.    , 1.    , 1.    , 1.    ],
       [1.    , 1.    , 1.    , 1.    ],
       ...,
       [1.    , 1.    , 1.    , 1.    ],
       [1.    , 1.    , 1.    , 1.    ],
       [1.    , 1.    , 1.    , 1.    ]]) 

I can't find any proper example in the docs and I do not know which shape the return values of cm.hot have to have (I tried various ways, alternatively with plt.scatter and the cmap/norm argument but same error)

How do I need to apply the cmap to get a line that gets continously brighter for later observations?

1

1 Answer 1

0

Try seaborn with scatter:

fig, ax = plt.subplots(1,1, figsize=(12,8))
ax.plot(arr[:,0], arr[:,1])
sns.scatterplot(arr[:, 0], arr[:, 1], 
                ax=ax, hue=arr[:,2], 
                palette=plt.cm.hot,
                legend=None)
plt.show()

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.