Bottom Page

• 1 Vote(s) - 5 Average
• 1
• 2
• 3
• 4
• 5
 matplotlib : Raster Plot adithyakrish Programmer named Tim Posts: 10 Threads: 3 Joined: Mar 2017 Reputation: 0 Likes received: 0 #1 Apr-24-2017, 10:46 AM (This post was last modified: Apr-24-2017, 01:00 PM by Larz60+. Edited 2 times in total.) 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  ``````Output:0 0 0 0 1 1 65536000 0 0 0 1 1 1 32768000 0 0 0 2 1 1 32768000 0 0 1 0 3 1 65536000 0 1 1 0 2 1 32768000 0 2 1 0 2 2 32768000 0 0 2 0 3 2 -65536000 0 0 0 1 0 1 163840000 0 1 0 2 0 1 163840000 0 2 0 3 0 1 163840000 0 3 0 0 0 1 163840000``````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!  Larz60+ wrote Apr-24-2017, 01:00 PM:Please use code tags in the future see BBCODE heiner55 Verb Conjugator Posts: 605 Threads: 3 Joined: Nov 2016 Reputation: 27 Likes received: 29 #2 May-28-2019, 05:04 AM ```#!/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() ``` « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post How to create a new plot in a figure right below the first one after click event? codexx 1 110 May-26-2019, 12:52 PM Last Post: heiner55 Plot a function dxfrelince 3 124 May-21-2019, 12:23 PM Last Post: DeaD_EyE Issues with matplotlib.pyplot schniefen 2 172 Apr-19-2019, 11:51 AM Last Post: schniefen How do I make my plot show up? ThomasM4 0 305 Dec-09-2018, 05:28 AM Last Post: ThomasM4 Tips on surface plot HW question Cwcox 1 370 Nov-14-2018, 11:45 PM Last Post: Larz60+ How to customize x axis in matplotlib.pyplot for a scatter plot? wlsa 9 851 Nov-10-2018, 01:32 AM Last Post: wlsa How to create custom error bars in matplotlib.pyplot? wlsa 1 582 Nov-04-2018, 09:49 PM Last Post: wlsa Adding text to plot Pythcoronas 1 443 Sep-13-2018, 12:27 PM Last Post: baby_quant plot the mean in a bar diagram sussii 3 572 May-23-2018, 11:27 PM Last Post: wavic How to plot date series in matplotlib? StrybolData 2 2,578 Jan-25-2018, 07:13 PM Last Post: StrybolData

Forum Jump:

Users browsing this thread: 1 Guest(s)