0

I have this set of data:

{5: 136018, 4: 131402, 6: 113441, 7: 94609, 8: 80752, 9: 69753, 10: 60322, 11: 51388, 
12: 44416, 13: 37638, 14: 31524, 15: 26275, 16: 22098, 17: 18458, 18: 15294, 19: 12207, 
20: 10209, 21: 8355, 22: 6826, 23: 5657, 24: 4554, 25: 3668, 26: 2907, 27: 2438, 28: 1923, 
29: 1609, 30: 1223, 31: 1000, 32: 821, 33: 693, 34: 492, 35: 381, 36: 315, 37: 263, 38: 218,
40: 170, 39: 164, 41: 103, 42: 94, 43: 58, 44: 48, 45: 40, 47: 36, 46: 30, 49: 22, 48: 21, 
50: 14, 51: 12, 53: 9, 52: 6, 54: 5, 55: 5, 56: 4, 57: 3, 64: 2, 58: 1, 59: 1, 60: 1, 
61: 1, 62: 1, 65: 1, 66: 1}

What I want to do is create an image from this data. I know its not going to be easy, but basically I want to use something like PIL to create an image, I want to show kind of a bar graph with it, I know it would also be a huge image because of the big numbers (like 136018)

So how the heck would I possibly do this with Python and PIL?

0

3 Answers 3

4

The hard way. Use matplotlib instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Could you give me an example of creating a bar graph with it?
Sweet as. Thanks for that, I will check it out.
3

Ignacio's advice is good - but here is a simpler example to get you started:

import pylab    # part of the matplotlib package - a simpler interface

data = {
    5: 136018, 4: 131402, 6: 113441, 7: 94609, 8: 80752, 9: 69753,
    10: 60322, 11: 51388, 12: 44416, 13: 37638, 14: 31524, 15: 26275,
    16: 22098, 17: 18458, 18: 15294, 19: 12207, 20: 10209, 21: 8355,
    22: 6826, 23: 5657, 24: 4554, 25: 3668, 26: 2907, 27: 2438, 28: 1923,
    29: 1609, 30: 1223, 31: 1000, 32: 821, 33: 693, 34: 492, 35: 381,
    36: 315, 37: 263, 38: 218, 40: 170, 39: 164, 41: 103, 42: 94, 43: 58,
    44: 48, 45: 40, 47: 36, 46: 30, 49: 22, 48: 21, 50: 14, 51: 12,
    53: 9, 52: 6, 54: 5, 55: 5, 56: 4, 57: 3, 64: 2, 58: 1, 59: 1, 60: 1,
    61: 1, 62: 1, 65: 1, 66: 1
}

xs = range(min(data), max(data)+1)
ys = [data.get(x, 0) for x in xs]

pylab.bar(xs, ys)

gives you enter image description here

Comments

1

Try something like this: You'll have to modify the pixels part naturally

import PIL

image = PIL.Image.new('RGBA', (1000, 1000))
pixels = image.load()

print pixels[x, y]
pixels[x, y] = some_color

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.