[英]How to pass color as a function parameter in python
我在 python 中创建了一个 function 如下:
def confidence_ints(df, color):
time_series_df = pd.DataFrame(df)
smooth_path = time_series_df.rolling(20).mean()
path_deviation = time_series_df.rolling(20).std()
plt.plot(smooth_path, linewidth=2)
plt.fill_between(path_deviation.index, (smooth_path-2*path_deviation)[0],
(smooth_path+2*path_deviation)[0], color=color, alpha=.1)
return
我想为不同的数据帧多次调用 function 和 plot 特定于 colors 每个 df。 但是,当我使用以下代码调用 function 时:
confidence_ints(dfmel_statsT_HEL, green)
我收到以下错误:
NameError:名称“绿色”未定义
我该如何正确地做到这一点?
谢谢。
尝试
confidence_ints(dfmel_statsT_HEL, 'green')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.