Change the axis length of a plot to make the diagrams look better in Python
<p>I used the following code in Python to plot four vectors. However, as you can see the plot does not look nice as different curves stick to each other in some points and they are very close to each other. How can I change the plot so that the curves get separated better and the plot look better?</p>

<pre><code>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()
</code></pre>

<p><a href="http://i.stack.imgur.com/il4xA.png" rel="nofollow"><img src="http://i.stack.imgur.com/il4xA.png" alt="enter image description here"></a></p>

<p>How about separating them into four subplots?</p>

<p><a href="http://i.stack.imgur.com/46bl5.png" rel="nofollow"><img src="http://i.stack.imgur.com/46bl5.png" alt="enter image description here"></a></p>

<p>You could mimic a seaborn/ggplot/pandas style just using matplotlib like:</p>

<pre><code>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, )
</code></pre>

<hr>

<p>Or, so you can still do same-plot comparisons, maybe you could use alpha to individually highlight each line with the others in the background:</p>

<p><a href="http://i.stack.imgur.com/NkwXz.png" rel="nofollow"><img src="http://i.stack.imgur.com/NkwXz.png" alt="enter image description here"></a></p>

<pre><code>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')
</code></pre>

python matplotlib plot