`Hi John
`
`> Not sure what you are doing wrong, but here’s
an example I just tested
that created two PNGs with the indicated sizes in pixels (verified
in
the GIMP)
from pylab import *
Perhaps you can adapt it to your code.
`
I tested it on my system and it did as it should. So I started to strip down my code to the basics. Replacing/Adding bit by bit. One error might have been that I used _F_igure() instead of _f_igure(). But the problem didn't go away. So I removed all "references" (var: fig) to the created figure... and it worked from then on...
Thanks John to bringing me back to the basics... but I still don't know what the reason was!
Merry greetings,
Marco - goes now after bug squashing to a real Squash session 8o)
The working code:
import matplotlib
matplotlib.use('Agg') # Agg, Cairo, GTK, GTKAgg, GTKCairo, PS, TkAgg, WX, WXAgg, Paint, GD, Template
from pylab import *
def create_png(filename, width_in_pixel, height_in_pixel):
bar_colors = ["#E3E3AA", "#BFE0FF", "#FFE8C4", "#C6DFDA", "#D9D1EB"]
bar_performances = [0.705, 1.757, 1.057, -0.635, -1.347]
bar_descriptions = ('Scenario 1\nExpected\n%.2f%%', 'Scenario 2\nBest case\n%.2f%%', 'Scenario 3\nBoom\n%.2f%%', 'Scenario 4\nRecession\n%.2f%%', 'Scenario 5\nWorst case\n%.2f%%')
dpi = 100
figure(figsize=(int(width_in_pixel / dpi), int(height_in_pixel / dpi)))
for b_num, b_perf in enumerate(bar_performances):
bar((b_num + 0.55,), (b_perf,), width=.9, color=bar_colors[b_num])
# Place the text in the middle of the bar
t = text(b_num + 1, b_perf / 2.0, bar_descriptions[b_num] % b_perf,
`
horizontalalignment='center', `
`
verticalalignment='center',`
`
size=9)`
gca()
grid(True)
xticks(arange(1,6), [''] * 5)
ylabel('Performance %')
draw() # force a draw
savefig(filename, dpi=100)
if __name__ == '__main__':
create_png('c:/temp/aaaaa_scenarios_600_300.png', 600, 300)
create_png('c:/temp/aaaaa_scenarios_600_800.png', 600, 800)
create_png('c:/temp/aaaaa_scenarios_800_600.png', 800, 600)
create_png('c:/temp/aaaaa_scenarios_1000_200.png', 1000, 200)