Python Forum
Plot arrays against each other
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plot arrays against each other
#1
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
Reply
#2
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?
Reply
#3
(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.
Reply
#4
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to plot intraday data of several days in one plot mistermister 3 2,918 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  How to plot vertically stacked plot with same x-axis and SriMekala 0 1,932 Jun-12-2019, 03:31 PM
Last Post: SriMekala
  How to plot histogram from 2 arrays? python_newbie09 5 8,811 Mar-28-2019, 04:20 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020