![]() |
Plot arrays against each other - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Plot arrays against each other (/thread-34894.html) |
Plot arrays against each other - fabstr1 - Sep-13-2021 Hello, I have a question of how I can plot the two arrays against each other from the link below. The array on the top should be plotted against the other array below it, but how do I fix the mismatch between them? When I try to plot them, I got this error message "TypeError: unhashable type: 'numpy.ndarray'" import csv import itertools import pandas import numpy as np import pandas as pd import matplotlib.pyplot as plt #for time_seconds in range(1878820): #for time_seconds in range(1527): # time = time_seconds #print(time) time = np.arange(0, 1527, 1) time_transposed = np.c_[time] print(time_transposed) with open("out_isi.txt", mode='r') as f: # data = csv.reader(f, delimiter=' ', quotechar='|') data = csv.reader(f) my_data = list(data) print(my_data) plt.plot(time_transposed, my_data) plt.show()https://i.imgur.com/FbjPszX.png RE: Plot arrays against each other - deanhystad - Sep-13-2021 My first thought is don't call np.c_ to transpose the time array. Just call plt.plot(time, my_data). Why do you think you need to transpose the time array? RE: Plot arrays against each other - fabstr1 - Sep-14-2021 (Sep-13-2021, 03:08 PM)deanhystad Wrote: My first thought is don't call np.c_ to transpose the time array. Just call plt.plot(time, my_data). Why do you think you need to transpose the time array? I removed the transpose of the time array and I got the error message "TypeError: unhashable type: 'numpy.ndarray'". I forgott to remove the transpose from my previous code. RE: Plot arrays against each other - deanhystad - Sep-14-2021 This works fine for me: import math import numpy as np import matplotlib.pyplot as plt degrees = np.arange(0, 360, 1) my_data = [math.sin(math.radians(deg)) for deg in degrees] plt.plot(degrees, my_data) plt.show()Both my_data and degrees look like flat lists. My guess is csv_reader is returning something other than a flat list. What do you see when you print my_data? |