显示matplotlib线图中的所有线

时间:2018-12-02 19:35:10

标签: python matplotlib

如何将另一行放在最前面或同时显示两个图?

plot_yield_df.plot(figsize=(20,20))

output

2 个答案:

答案 0 :(得分:1)

如果绘图数据重叠,则查看两种数据的一种方法是增加线宽以及处理透明度,如下所示:

list = who;
for k=1:length(list)
    if ismatrix(eval(list{k})) && all(size(eval(list{k})) == [M, N])
        eval([list{k},'_new = ',list{k},'(1:2:end,1:3:end);']);
    end
end

plt

子绘图是另一种好方法。

答案 1 :(得分:0)

问题

以线条在数据框中出现的顺序绘制线条。例如

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

a = np.random.rand(400)*0.9
b = np.random.rand(400)+1
a = np.c_[a,-a].flatten()
b = np.c_[b,-b].flatten()
df = pd.DataFrame({"A" : a, "B" : b})

df.plot()

plt.show()

enter image description here

此处"B"的值对"A"隐藏。

解决方案1:反向列顺序

一个解决方案是颠倒他们的顺序

df[df.columns[::-1]].plot()

enter image description here

这也改变了图例和颜色编码的顺序。

解决方案2:反向z顺序

因此,如果不需要的话,您可以改为使用zorder。

ax = df.plot()

lines = ax.get_lines()
for line, j in zip(lines, list(range(len(lines)))[::-1]):
    line.set_zorder(j)

enter image description here