0

Just as the title says, is there a way to make a 2D plot using matplotlib.pyplot? something like the following snippet:


import numpy as np
imprt matplotlib.pyplot as mp

t = np.linspace(0,200,200)
x = np.array([ np.cos(i/(6.28)) for i in range(-100,100)])
y = np.array([ np.sin(i/(6.28)) for i in range(-100,100)])

mp.plot(x,y, color=SOME_WAY_TO_VARY_COLOR_WITH_T(t))
mp.show()

The goal is to have the output plot to change colors with respect to t, or normalized from 0 to 1 where something like blue would be 0 and red would be 1.

Any help would be appreciated!

  • 1
    This question has been asked before; see [here](https://stackoverflow.com/questions/10252412/matplotlib-varying-color-of-line-to-capture-natural-time-parameterization-in-da) and [here](https://stackoverflow.com/questions/52884221/how-to-plot-a-matplotlib-line-plot-using-colormap) – Warren Weckesser Sep 05 '21 at 14:02
  • Also, take a look at https://matplotlib.org/stable/gallery/lines_bars_and_markers/multicolored_line.html#sphx-glr-gallery-lines-bars-and-markers-multicolored-line-py – Warren Weckesser Sep 05 '21 at 14:06

0 Answers0