0

I have plotted two columns from a csv file using plt.plot and have achieved the following graph:

enter image description here

The code for the graph is the following:

plt.plot(x, y, linewidth=0.50)

I have another column within the same csv file that contains the time for each of the x and y values. The time column looks like this:

Time,
1000,
2000,
3000,
4000,
5000,
6000,
7000,
etc...

I want to impose the time column to act as the color-code for the lines so that they can be coloured according to the time. I have tried this with a scatterplot and it works great...

enter image description here

...by tweaking the code to this...

plt.scatter(x, y, c=-x, s=10)
plt.gray()

...but I can't get it to work with a normal line plot.

6
  • The easiest solution is the use seaborn.scatterplot and set hue='Time'. seaborn is a high-level api for matplotlib. Commented Aug 26, 2021 at 15:20
  • Yes I managed to do that, but how do I plot a line graph and do the same? Commented Aug 26, 2021 at 15:29
  • with seaborn.lineplot and hue I would guess. Or plot the scatterplot on the lineplot by calling the two plots sequentially. Commented Aug 26, 2021 at 15:29
  • 2
    Can't do much else to help you since the question doesn't have a complete minimal reproducible example. Commented Aug 26, 2021 at 15:31
  • 1
    See matplotlib.org/stable/gallery/lines_bars_and_markers/… Commented Aug 26, 2021 at 15:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.