Question

Is there a way to set parameters for multiple graphs at once - basically defining a default?

What I have right now:

fig = plt.figure()
ax1 = fig.add_subplot(313)
ax1.scatter(entries,gvalues[0], color='b', marker = '1')
ax1.scatter(entries,gvalues[1], color = 'g', marker = 'v')
xticks([z for z in range(N)], namelist)
ylabel('Label1', ha='center', labelpad=28)
ylim(0,)
ax2 = fig.add_subplot(312, sharex=ax1)
ax2.scatter(entries,gvalues[2], color = 'b', marker = '1')
ax2.scatter(entries,gvalues[3], color= 'g', marker = 'v')
ylabel('Label2', ha='center', labelpad=28)
setp(ax2.get_xticklabels(),visible=False)
ylim(0,)

I am going to have a handful of these graphs, and it would be great if I didn't have to set ha = 'center', labelpad = 28 and ylim(0,) everytime.

Cheers

Was it helpful?

Solution

You can use a dictionary to store your options as below:

font_options = dict(ha='center', labelpad=28)

ax1.set_ylabel('Label1', **font_options)

...

ax2.set_ylabel('Label2', **font_options)

The **font_options argument will unpack each of the key-value pairs in the dictionary and apply them within the ylabel function.

Similarly for the ylim option you can store your limits in a variable such as:

ylimit = 0

ylim(ylimit,)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top