Reputation: 20557
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?
Upvotes: 0
Views: 142
Reputation: 56624
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
Upvotes: 3
Reputation: 80011
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
Upvotes: 1