我有关于pandas DataFrame中时间序列的数据,我想为这些行提供单独的标记.到目前为止,我只使用marker =’o’参数设法对两行使用相同的标记.
我正在使用http://stanford.edu/~mwaskom/software/seaborn/tutorial/timeseries_plots.html#specifying-input-data-with-long-form-dataframes中的示例,我复制了我复制并粘贴下面的代码.
如何为每条线绘制单独的标记?
import numpy as np
np.random.seed(9221999)
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(palette="Set2")
def gamma_pdf(x, shape, coef, obs_err_sd=.1, tp_err_sd=.001):
y = stats.gamma(shape).pdf(x) * coef
y += np.random.normal(0, obs_err_sd, 1)
y += np.random.normal(0, tp_err_sd, len(x))
return y
gammas = []
n_units = 20
params = [(5, 1), (8, -.5)]
x = np.linspace(0, 15, 31)
for s in range(n_units):
for p, (shape, coef) in enumerate(params):
y = gamma_pdf(x, shape, coef)
gammas.append(pd.DataFrame(dict(condition=[["pos", "neg"][p]] * len(x),
subj=["subj%d" % s] * len(x),
time=x * 2,
BOLD=y), dtype=np.float))
gammas = pd.concat(gammas)
sns.tsplot(gammas, time="time", unit="subj",
condition="condition", value="BOLD", marker="o")
plt.show()
解决方法:
你必须在每个级别的条件变量中调用tsplot两次,或者你可以用这种方式绘制,然后对绘图数据进行事后处理:
ax = sns.tsplot(gammas, time="time", unit="subj",
condition="condition", value="BOLD", marker="o")
ax.lines[-1].set_marker("s")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。