简体   繁体   中英

Pyplot: Cmap(index) -> color function

Suppose I have the following:

data_mats = [ ... ]

# pseudo code
cmap = plt.(...).get_cmap('magma', low=0, high=len(data_mats))

for i in range(0,len(data_mats)):

    # pseudo code
    color = cmap(i)

    mat = data_mats[i]
    plt.plot(mat[:,1],mat[:,2], color=color)

How do I fill in the lines of pseudo code:

# lines of pseudo code
cmap = plt.(...).get_cmap('magma', low=0, high=len(data_mats))

color = cmap(i)

Using pyplot?

(why all the dense examples on matplotlib's website, rather than some code specs?)

import matplotlib.pyplot as plt

i = 10
file_ct = 100

cmap = plt.cm.magma
color = cmap(float(i+1) / float(file_ct)) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM