简体   繁体   English

在Matlab中Python相当于get(,'color')函数

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

I am a newbie in Python. 我是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: 我想实现与下面的Matlab代码非常相似的东西,但仍受其Python等效项的限制:

...
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. 看看matplotlib进行绘图。 Then, you can use get_color() for line objects. 然后,可以将get_color()用于线对象。

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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