Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pandas,matplotlib:一种为子地块中的相同列标签指定相同颜色和线样式的方法?_Python_Pandas_Matplotlib_Linestyle - Fatal编程技术网

Python pandas,matplotlib:一种为子地块中的相同列标签指定相同颜色和线样式的方法?

Python pandas,matplotlib:一种为子地块中的相同列标签指定相同颜色和线样式的方法?,python,pandas,matplotlib,linestyle,Python,Pandas,Matplotlib,Linestyle,我有几个数据框,显示了一些具有随时间变化的类似变量(即列名)的对象,我正在子图中绘制它们 >>df1.head() FR stim_current self_excitation FF_inh SFA 1 0.000000 0.0 0.000000 -0.075483 -0 2 0.000000 0.0 0.000000 -0.000000 -0 3 -0.00001

我有几个数据框,显示了一些具有随时间变化的类似变量(即列名)的对象,我正在子图中绘制它们

>>df1.head()


         FR  stim_current  self_excitation    FF_inh  SFA
1  0.000000           0.0         0.000000 -0.075483   -0
2  0.000000           0.0         0.000000 -0.000000   -0
3 -0.000012           0.0         0.000000 -0.001761   -0
4 -0.000033           0.0        -0.000009 -0.003487    0
5 -0.000064           0.0        -0.000027 -0.005178    0

>>df2.head()

      FR    FB_inh  stim_current  self_excitation
1  0.000000 -0.001569             1         0.000000
2  0.017609 -0.000000             1         0.000000
3  0.034867 -0.000200             1         0.010037
4  0.051780 -0.000577             1         0.019874
5  0.068355 -0.001109             1         0.029515

是否有办法通过列名指定线条样式,以便,例如,FR、stim_电流和自激在每个子批次中具有相同的颜色?假设我希望FR为蓝色和粗体,stim电流为黑色,自激为绿色。我还希望数据帧之间的任何差异在每个子图上以不同的颜色显示。理想情况下,我还可以对数据框的列进行重新排序,以便每个数据框中显示的内容都位于顶部的图例中,而变化的内容则位于图例的底部。

通过以下方法,可以在不同子地块之间使用一致的颜色和线条样式

import matplotlib.pyplot as plt
import numpy as np

# load your pandas DataFrames  df1 and df2 here 

ax = [plt.subplot(211), plt.subplot(211)]
pars = {'FR': {'color': 'r'},
        'stim_current': {'color': 'k'}}
ls_style = ['dashed', 'solid']
for ax_idx, name in enumerate(['FR', 'stim_current']):
    for df, ls in zip([df1, df2], ls_style):
        ax[ax_idx].plot(df.index, df[name], ls=ls, **pars[name])