matplotlib : Raster Plot - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: matplotlib : Raster Plot (/thread-3005.html) |
matplotlib : Raster Plot - adithyakrish - Apr-24-2017 Hey Everyone, I am stuck at a point whee I need a simple python code generate a raster plot based on the values that is generated as the output of the dictionary. The code for the dictionary is: f = open('input.txt') lines = f.readlines() dict = {} cnt = 1 for l in lines: ind = l[0]+l[2]+l[4] if ind not in dict: dict[ind] = cnt cnt = cnt + 1 sorted_dict = sorted(dict.items(), key=operator.itemgetter(1)) for t in sorted_dict: print(t)The "input.txt" is I need the first three columns alone. I need to remove repetition and number them in the order. For example, "0 0 0" becomes 1, "0 0 1" become 2, "0 1 1" becomes three. (In the same order as mentioned in the file)Now, i need to plot a Raster Plot with the assigned numbers on my X axis and and the three digit value ("0 0 0", "0 0 1" and so on) as my Y axis. Please help me guys.. I have no idea of how to plot a raster! RE: matplotlib : Raster Plot - heiner55 - May-28-2019 #!/usr/bin/python3 import operator import matplotlib import matplotlib.pyplot as plt f = open('input.txt') lines = f.readlines() dict = {} cnt = 1 for l in lines: ind = l[0]+l[2]+l[4] if ind not in dict: dict[ind] = cnt cnt = cnt + 1 sorted_dict = sorted(dict.items(), key=operator.itemgetter(1)) for t in sorted_dict: print(t) plt.plot(*zip(*sorted_dict)) plt.show() |