0

I have one data file which is like this:

1, 23%
2, 33%
3, 12%

I want to use python to generate one histogram to represent the percentage. I followed these command:

from PIL import Image
img = Image.new('RGB', (width, height))
img.putdata(my_data)
img.show()

However I got the error when I put the data: SystemError: new style getargs format but argument is not a tuple. Do I have to change my data file? and How?

technoob
  • 37
  • 1
  • 1
  • 4
  • http://stackoverflow.com/questions/12062920/how-do-i-create-an-image-in-pil-using-a-list-of-rgb-tuples – Mani Apr 14 '16 at 13:02

2 Answers2

0

Are you graphing only? PIL is an image processing module - if you want histograms and other graphs you should consider matplotlib.

I found an example of a histogram here.

dodell
  • 470
  • 3
  • 7
0

A histogram is usually made in matplotlib by having a set of data points and then assigning them into bins. An example would be this:

import matplotlib.pyplot as plt

data = [1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 7]
plt.hist(data, 7)
plt.show()

You already know what percentage of your data fits into each category (although, I might point out your percentages don't add to 100...). A way to represent this is to to make a list where each data value is represented a number of times equal to its percentage like below.

data = [1]*23 + [2]*33 + [3]*12
plt.hist(data, 3)
plt.show()

The second argument to hist() is the number of bins displayed, so this is likely the number you want to make it look pretty.

Documentation for hist() is found here: http://matplotlib.org/api/pyplot_api.html

kingledion
  • 2,263
  • 3
  • 25
  • 39