davidfokkema / artist

Artist makes beautiful plots
http://davidfokkema.github.io/artist/
GNU General Public License v3.0
12 stars 2 forks source link

Automatically set aspect ratio of plot for bitmap #19

Closed 153957 closed 9 years ago

153957 commented 9 years ago

When using draw_image it might be nice if the plot (data area) aspect ratio matches the bitmap. To make the axes fit snugly around the bitmap. This is not trivial with the width/height keywords, these seem to include ticks or some padding..

For Utrecht demo the bitmap is 768x512 (= 3:2), however, the set Plot width and height ratio to get a nice fit are 7:5.

With improper aspect ratio letterboxing (empty plot area within the axes) will occur.

153957 commented 9 years ago

Perhaps this can be fixed now 38854e4b43a2d3604172e785802dd30b89dd9de1

153957 commented 9 years ago

To much work for now. We will leave it as an exercise to the user to manually set the correct width-height ratio.

153957 commented 9 years ago

Hint:

image = Image.open('foo.png')
aspect = float(image.size[0]) / float(image.size[1])
width = .67
height = width / aspect

graph = Plot(width =r'%.2f\linewidth' % width, height=r'%.2f\linewidth' % height)
graph.draw_image(image, 0, 0, image.size[0], image.size[1])