ich habe hier eine Methode, die einen Bar-Plot erzeugt. Wenn ich diese Methode mehrfach aufrufen möchte, soll sie jeweils eine Datei des Plots speichern, aber jedes Mal unter einem 'anderem' Namen.
Ich hoffe, ihr wisst was ich meine.
Hier meine Methode:
Code: Alles auswählen
def build_the_figure(self, x_axis_content, y_axis_content, number_of_extra_bars, extra_bar_content, extra_bar_legend, x_label, y_label, extra_y_label):
fig = plt.figure()
ax1 = fig.add_subplot(111)
N = len(x_axis_content)
ind = np.arange(N)
width = 0.15
rects = ax1.bar(ind + width, y_axis_content, width, color = 'k' )
if number_of_extra_bars != None:
length = number_of_extra_bars + 1
for i in range(1, length):
for rect in rects:
ax2 = ax1.twinx()
rect = ax2.bar(ind + (i+1)*width, extra_bar_content, width, color = 'r')
ax1.set_xlabel(str(x_label))
ax1.set_ylabel(str(y_label))
ax2.grid(color = 'grey', linestyle='-', linewidth = 0.09)
ax2.set_ylabel(str(extra_y_label))
plt.xticks(ind + width, x_axis_content)
leg = plt.legend((rects[0], rect[0]), (str(y_label), str(extra_bar_legend)))
for t in leg.get_texts():
t.set_fontsize('small')
else:
rects = ax1.bar(ind + width, y_axis_content, width, color = 'r')
ax1.set_xlabel(str(x_label))
ax1.set_ylabel(str(y_label))
ax1.grid(color = 'grey', linestyle='-', linewidth = 0.09)
plt.xticks(ind + width, x_axis_content)
fig.savefig(sys.path[0])
return rects
Grüßle
Isa