Rezney - 1 year ago 67

Python Question

How to avoid plot line merging with plot frame in matplotlib? I attached a screenshot. As you can see the purple line at the bottom is merely visible.

Graph

I am plotting like this:

`plt.subplot2grid((4,4), (1, 0), colspan=2)`

plt.plot(np.array(graph_time), np.array(graph1_data), label="graph1", color='#a42102')

plt.plot(np.array(graph_time), np.array(graph2_data), label="graph2", color='#da7701')

if len(errortime) > 0:

[plt.axvline(_x, linestyle="dashed", color='r', label='error' if not i else None, zorder=5) for i, _x in enumerate(errortime)]

lgd = plt.legend(ncol=2, loc='best')

lgd.get_frame().set_alpha(0)

plt.xticks(rotation=30)

Any help is much appreciated...thanks!

Answer Source

The easiest thing to do would be to alter the axes. If you move the y-axis down to about -5 or even -1 it will show the whole line. Use the ylim function:

```
ymin, ymax = ylim() # get the current limits
ylim( (ymin - 5, ymax) ) # set the ylim to ymin, ymax
```

This will move the y-axis down by 5. If you want to do this in such a way that it scales well to larger graphs you could do something like this:

```
ymin, ymax = ylim()
ymin = ymin - (ymax -ymin)* 0.1
ylim( (ymin, ymax) )
```