0

I have a text file that contain 2048 rows and 256 columns, i want to plot only 10 columns of data in an subplot,

I tried

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


data=np.loadtxt("input_data.txt")
data=data[:,0:10]
print(data.shape)


nrows=5
ncols=10
fig, axs = plt.subplots(nrows,ncols, figsize=(13,10))
count = 0
for i in range(ncols):
    for j in range(nrows):
        axs[i,j].plot(data[count])
        count += 1
        print(count)        
plt.show()

But it doesnot plot the each column values, I hope experts may help me.Thanks.

  • The question isn't clear. You want to plot 10 columns in 10 different subplots or in a single subplots. Also why did you write `nrows=5, ncols=10` this will result in 50 plots. – Prakhar Sharma Sep 13 '22 at 11:37
  • 1
    @PrakharSharma i want to plot 10 columns in 10 different subplot – user19520518 Sep 13 '22 at 11:40
  • 1
    Welcome to StackOverflow. Please take the [tour](https://stackoverflow.com/tour) and learn [How to Ask](https://stackoverflow.com/help/how-to-ask). In order to get help, you will need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). If your question include a pandas dataframe, please provide a [reproducible pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – alec_djinn Sep 13 '22 at 12:14

1 Answers1

1

I used random numbers to reproduce your problem.

data=np.random.randint(0,1,size = (2048,256))
data=data[:,0:10]
print(np.shape(data))

nrows=2
ncols=5
fig, axs = plt.subplots(nrows,ncols, figsize=(13,10))
count = 0
for i in range(nrows):
    for j in range(ncols):
        print(count)
        axs[i,j].plot(data[:,count])
        count += 1

Here is your plot.

enter image description here

if you put real data you will see some variation in each subplot.

Prakhar Sharma
  • 543
  • 9
  • 19