I have some data and want to read the 5th and 6th column so to plot the 2D histogram of it. I have written the following code but it fails. I would be appreciated if someone can help me in this process.
There is a dimensional error message that I don't understand, something like, "The dimension of bins must be equal to the dimension of the sample x."
I have provided the code that I've tried. Any suggestion is much appreciated.
Here is the link to my sampled data.
https://gofile.io/d/U4NT0e[
^]
What I have tried:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
path = r'D:\test_file\data\final.txt'
df = pd.read_csv( path , header = None, sep = ' ', dtype = float, engine = 'python')
df1 = df[4].to_string()
df2 = df[5].to_string()
lmin = -1
lmax = 1
nbins = 100
xedge = np.linspace(lmin, lmax, nbins + 1)
yedge = np.linspace(lmin, lmax, nbins + 1)
fxyz = np.zeros((nbins,nbins))
weight = None
hist,xedges,yedges=np.histogram2d(df1, df2, bins=(xedge,yedge), normed=True, weights=weight)
fxyz += hist.T
extent = (xedges[0],xedges[-1],yedges[0],yedges[-1])
with np.errstate(divide='ignore',invalid='ignore'):
plt.figure(figsize=(10,6))
images = plt.imshow(np.log10(fxyz), origin='lower', extent=extent,cmap='jet')
plt.ylim(0,0.7); plt.xlim(-0.7,0.7)
plt.show()