2016-08-26 11 views
1

Pythonで次のコードを使用して4つのベクトルをプロットしました。しかし、あなたが見ることができるように、いくつかの点では、異なる曲線が互いに張り付いているので、プロットはうまく見えず、互いに非常に近いです。どのようにして、曲線がより良く分離され、プロットがよりよく見えるようにプロットを変更できますか? 4つのサブプロットにそれらを分離することについてプロットの軸の長さを変更して、図をPythonでよりよく見えるようにする

plt.gca().set_color_cycle(['red', 'green','blue','purple']) 
plt.plot(UB_user_util_list) 
plt.plot(UB_Greedy_user_util_list) 
plt.plot(IB_user_util_list,) 
plt.plot(IB_Greedy_user_util_list) 
plt.legend(['UB', 'UB_Optimized','IB','IB_opimized'], loc='upper left') 
plt.title("User Utility values over time/split data based on time") 
plt.show() 

enter image description here

+0

あなたはもっと大きなプロットを持っていますか? 'plt.figsize(12,16)'?もし彼らが同じ姿にいなければならないのでしょうか? – putonspectacles

答えて

0

どのように?

enter image description here

あなただけのようmatplotlibの使用seaborn/ggplot /パンダのスタイルを模倣することができます:あなたはまだ同じプロットの比較を行うことができますので、多分あなたは使用することができ、

import matplotlib as mpl 
import matplotlib.pyplot as plt 
import numpy as np 
mpl.rcParams['axes.linewidth'] = 0.0 

vex = (np.random.rand(100),)*4 
v_attr = [('r','v1'), ('orange', 'v2'), 
      ('g', 'v3'), ('b', 'v4')] 

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', 
                sharey='row') 

for s,v,(c,l) in zip([ax1, ax2, ax3, ax4], vex, v_attr): 
    s.set_axis_bgcolor('#dddddd') 
    s.grid(b=True, which='major', c='white', ls='-', zorder=-1, 
      lw=0.75, alpha=0.64) 
    s.set_ylim(0,max(v)*1.35) 
    s.tick_params('both', pad=4, labelsize=8, which='major', 
        direction='out', top='off', right='off') 
    s.plot(v, label=l, c=c, zorder=3) 
    s.legend(frameon=False,) 

かアルファを使用して、各ラインを背景内の他のラインと個別にハイライト表示します。

enter image description here

import numpy.random as rand 

def rand_line(): 
    return rand.normal(rand.randint(5,12), 
         rand.ranf()*3, 100) 

lines = [rand_line() for _ in range(4)] 
labels = [('r','v1'), ('purple','v2'), 
      ('g','v3'), ('b','v4')] 

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', 
                sharey='row') 
subplots = [ax1, ax2, ax3, ax4] 
for i,s in enumerate(subplots): 
    for j,(v,l) in enumerate(zip(lines,labels)): 
     a = (.9 if j==i else 0.25) 
     s.plot(v, zorder=3, alpha=a, c=l[0], label=l[1]) 
    s.legend(loc='lower center', ncol=4, fontsize=10) 

fig.tight_layout() 
plt.savefig('line_subplots-highlight.png') 
+0

私はそれらを比較のために同じプロットにしたい – HimanAB

関連する問題