0
votes

I was wondering if there was an option in matplotlib to have different colors along one graph. So far I manged to have a graph in a specific color as well as having multiple graphs in different colors.

However, all graphs I created so far have a singular color. I was wondering if I could use column c (see below) to color different parts of a graph.

In the example, I want to use the value "0.1" in column c with index 1 to color the graph from the first to the second data point, the value "0.2" in column c with index 2 to color the graph from the second to the third data point and so on.

data for one graph:
index  x  y  z  c
1      1  2  1  0.1
2      1  2  2  0.2
3      1  3  1  0.1

I found that I could color data points dependent on a fourth column in a 3D scatter plot and was wondering if that somehow works with line plots as well.

The only "workaround" I can think of is splitting my graph data into x sub-graphs (each subgraph data has only two data points - the start and end point) and color them according to the column c of the first data point. This would result in n-1 separate graphs for n data points however.

1
ah. so the workaround I thought of is the "normal" implementation. fair enough. - Cribber

1 Answers

0
votes

The solution for anyone still looking was splitting my graph data into x sub-graphs (each subgraph data has only two data points - the start and end point, or the nth and n+1th point).

Then I colored them according to the column c of the first data point. This results in n-1 separate graphs for n data points.

Further explanation here Line colour of 3D parametric curve in python's matplotlib.pyplot