Hi
Me once more. I am still working on
the problem. The figures / canvases have the proper sizes (see print-log)
but when they are saved, they will end up being 800x600 pixel pictures.
The print-statements show the following log:
Width: 2000
Height: 10000
dpi: 72
fig.get_dpi() = 72
Canvas size: (1944, 9936)
Figure size: (27.0, 138.0)
Width: 600
Height: 800
dpi: 72
fig.get_dpi() = 72
Canvas size: (576, 792)
Figure size: (8.0, 11.0)
Width: 800
Height: 600
dpi: 72
fig.get_dpi() = 72
Canvas size: (792, 576)
Figure size: (11.0, 8.0)
Width: 1000
Height: 200
dpi: 72
fig.get_dpi() = 72
Canvas size: (936, 144)
Figure size: (13.0, 2.0)
All the rendered pngs have a size of
800x600 pixels!!!
What the heck am I missing? Here the
latest 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
= 72
fig
= Figure(figsize=(width_in_pixel / dpi, height_in_pixel / dpi), dpi=dpi,facecolor="#D2D2D2")
canvas
= FigureCanvasBase(fig)
fig.add_subplot(111)
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
print
“- - - - - - - -”
print
“Width: %d” % width_in_pixel
print
“Height: %d” % height_in_pixel
print
“dpi: %d” % dpi
print
“fig.get_dpi() = %d” % fig.get_dpi()
print
"Canvas size: ", canvas.get_width_height()
print
"Figure size: ", fig.get_size_inches()
print
savefig(filename)
if name == ‘main’:
create_png('c:/temp/aaaaa_scenarios_2000_10000.png',
2000, 10000)
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)
Even more desperate greetings,
Marco