Best tool to generate specific graph from Python dict/JSON

I'm looking to make a specific graph layout from a specific **format** of **Python** data, but where the **data may be text, string, or another Python object**.

It has to be able to do it on the **fly**, and make visual formatting decisions based on whether the data is "the same" (regardless of numerically, text or another Python object).

It doesn't matter if Excel is used to make the image (*.xls or .csv) or ```matplotlib```or anything else.

***The coloring in the cells*** is based on whether the items within ```{1:"A", 2:"A"}```are **equivalent** (not the same object). **Green** for ```True```, **red** for ```False```. For example: ```"A" == "A"``` (as in the preceding sentences), or ```(10/5) == (20/10)```, or ```["A", 1, <test object at 0x1052c9b70>] == ["A", 1, <test object at 0x1052c9b70>]``` would all be green.

The text that appears in the cells is just the \__str__ representation of the object.

EDIT: I'm not so much looking for someone to do the work for me, but a recommendation of which tool (```XLS```, ```matplotlib```, ```whathaveyou```) would be best suited - and maybe a link to a tutorial on how to do some of those more difficult features (like the cell coloring).

I.e. ...
   
    {
        1000:{
              "Sample1":{1:"A", 2:"A"},
              "Sample2":{1:"A", 2:"A"},
              "Sample3":{1:"A", 2:"A"},
              },

        1001:{
              "Sample1":{1:"A", 2:"A"},
              "Sample2":{1:"A", 2:"A"},
              "Sample3":{1:"A", 2:"A"}
              },

        1002:{
              "Sample1":{1:"C", 2:"A"},
              "Sample2":{1:"A", 2:"A"},
              "Sample3":{1:"A", 2:"A"}
              },

        (...)

        9999:{
              "Sample1":{1:"A", 2:"T"},
              "Sample2":{1:"A", 2:"A"},
              "Sample3":{1:"A", 2:"G"}
              },
    }

Excel Example
LVL 3
Mike R.Asked:
Who is Participating?
 
Flabio GatesCommented:
perhaps with the help of xlsxwriter
import xlsxwriter

data = {
    1000:{
        "Sample1":{1:"A", 2:"A"}, 
        "Sample2":{1:"A", 2:"A"},
        "Sample3":{1:"A", 2:"A"},
    },
    1001:{
        "Sample1":{1:"A", 2:"A"}, 
        "Sample2":{1:"A", 2:"A"},
        "Sample3":{1:"A", 2:"A"}
    },
    1002:{
        "Sample1":{1:"C", 2:"A"}, 
        "Sample2":{1:"A", 2:"A"},
        "Sample3":{1:"A", 2:"A"}
    },
    9999:{
        "Sample1":{1:"A", 2:"T"}, 
        "Sample2":{1:"A", 2:"A"},
        "Sample3":{1:"A", 2:"G"}
    },
}



workbook = xlsxwriter.Workbook('foo.xlsx')
worksheet = workbook.add_worksheet()

greenbg = workbook.add_format({'bg_color': '#80FF80'})
redbg = workbook.add_format({'bg_color': '#FF8080'})
##greenbg = workbook.add_format({'bg_color': '#008000'})
##redbg = workbook.add_format({'bg_color': '#800000'})

worksheet.write(0, 1, "Sample1")
worksheet.write(0, 2, "Sample2")
worksheet.write(0, 3, "Sample3")

r = 1
for k in sorted(data):
    d = data[k]
    worksheet.write(r, 0, k)
    for i, kk in enumerate(sorted(d)):
        dd = d[kk]
        value = '%s/%s' % (dd[1], dd[2])
        format = greenbg if dd[1]==dd[2] else redbg
        worksheet.write(r, 1+i, value, format)
        
    r+=1

workbook.close()

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.