简体   繁体   中英

python plotting using matplotlib

I have a 2D matrix (ie 2 dimensional sequence of number) that I want to plot. the x axis are the numbers from 0 to 9 and the y axis is their frequency in n cases. n is variable so that the matrix has a fixed number of colomns(0-9) and n number of rows.

I named the matrix frequency_mat. Im plotting it using plt.plot(frequency_mat) its plotting it perfectly with all the 10 lines. I want to specify the line coloring however by giving a color sequence to it and specifying the colors from the first number (0) to the last number (9) by giving 10 colors in the color arrays. Whats the simplest way to do this? Thank you.

As from How to get different colored lines for different plots in a single figure?

You could set your color cycle in the order you wish to plot values. (This will maybe work for a matrix, otherwise simply plot the lines .plot(mat[0]), .plot(mat 1 ), ..., .plot(mat[9]))

import matplotlib.pyplot as plt

plt.gca().set_color_cycle(['red', 'green', 'blue', 'yellow']) 

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