0

I'm reading data from a file and I start by reading it with numpy.loadtxt() and then I change it to a dataframe using panda.DataFrame (If I don't read it at first with numpy the dataframe won't have 0,1,2...N columns for some reason and instead the first row of values becomes that row, but this is not the problem!).

This is the code and the result:

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

data=np.loadtxt("sqwasd.mat")
data=pd.DataFrame(data)

plt.imshow(data)
plt.show()

The beautiful colormap created

Here is the dataframe for those interested

Now the problem

The y-axis is in wrong units and I would need to multiply each Y value with a constant to display the correct units. This data is obtained from a simulation so I can't change in what units it gives the data. I have tried to read in the documentation but it seems like it is impossible to change axes' values in a colormap, with a normal graph I would just multiply the values I plot on the y-axis. I have also tried to use yticks but it doesn't help in this case since it only changes what is shown, not the units of the axis.

Am I trying to do something that isn't possible and in that case, is there any other way to achieve the same kind of result?

TheSack
  • 21
  • 2
  • `plt.imshow(data, origin='lower', extent=[x0,x1,y0,y1], aspect='auto')` is an often-used way to set the coordinates. Note that you shouldn't convert your data to a dataframe, but directly use your original data. – JohanC Feb 08 '22 at 20:57
  • I think you could use: `pd.read_csv` direclty and check options to have the first column as you want. Secondly it's seems that you might change the ticks in figure: with `plt.yticks(dataFrameRange, yourActualYCoordinates)` – Ulises Bussi Feb 08 '22 at 21:03

0 Answers0