简体   繁体   中英

Python's equivalent of get (,'color') function in Matlab

I am a newbie in Python. Please excuse my dummy question. I want to implement something very similar to the following Matlab code, but am stuck with its Python equivalents:

...
Subplot (2,1,1);
H = plot (rand(100,5));
C = get (H, 'Color')
H = area (myX, myY);
H(1).FaceColor = C1;
H(2).FaceColor = C2;
Grid on;
...

Could someone kindly shed me some lights? Thanks much in advance!

Have a look at matplotlib for plotting. Then, you can use get_color() for line objects.

this is a minimal example:

import numpy as np
import matplotlib.pyplot as plt
a=np.random.random((100,5))
fig, ax = plt.subplots()

lines=ax.plot(a)

#line_colors is a list of colors used for the lines in this plot. they are in string format, i.e. 'b' for blue etc.
line_colors=[l.get_color() for l in lines]

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