6

I'm currently creating many plots and some look great while other need some adjustment. From below how can I make the hard to see plot line easier to see without having to manually plot them? I plot 50-100 of these at a time then add them to a pdf report. I'd like to add space under the line, for example have ylim min limit set to -0.1, but do it automatically.

This one is hard to see plot line: Hard to see plot line

This one is easy to see plot line: Easy to see plot line

Here is my code for plotting:

def plot(chan_data):
'''Uses matplotlib to plot a channel
'''
f, ax = plt.subplots(1, figsize=(8, 2.5))
x = dffinal['time'].keys()    
ax.plot(x, dffinal[chan_data].values, linewidth=0.4, color='blue')
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d/%Y - %H:%M'))
ax.xaxis.set_major_locator(mdates.AutoDateLocator(interval_multiples=True))

lgd1 = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

f.autofmt_xdate()
ax.set_ylabel(dffinal[chan_data].name)
ax.grid('on')

#I've tried these with no luck
#ax.autoscale(enable=True, axis='y', tight=False)
#ax.set_ymargin(0.5)
#ax.set_autoscaley_on(True)

fname = ".\\plots\\" + chan_data + ".png"
print "Creating: " + fname
plt.savefig(fname, dpi=100, bbox_extra_artist=(lgd1,), bbox_inches='tight')
plt.close()
return fname    
1

1 Answer 1

13

You want margins doc

ex

ax.margins(y=.1)

Also see Add margin when plots run against the edge of the graph

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.