Spaces in file and matplotlib pyplot only plotting first 10 values

Viewed 21

I am using jupyter notebook to plot some data from a file that has a whole lot of space values between the two floats (x and y). For some reason, the plot that I output only outputs the first 10 values of the data set with lots of spaces.

The code works just file for another data file which does not have many spaces.

See below, the code and plot output for the file that works just fine (Ca_sr.World.avg_stddev.dat) and the code and plot output for the file that does not work well (Rep01_Cys239SG_ligandF1_dist.dat)

For the second (space-filled file) I have resorted to naming the spaces s1, s2, sn... and think that this may be the problem. Still not sure why this would only plot the first 10 lines of the data, though. To note, I have also tried to put an xlim value and it didn't work either.

Would greatly appreciate any help or suggestions!

import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import os
import glob
import gc
prefix_file='~/Desktop/'
file_name='Ca_sr.World.avg_stddev.dat'

# plot a file (standalone from dataset)
filename=prefix_file + file_name
readfile= pd.read_csv(
    filename,
    delimiter=' ',
    names=['x', 'y', 's'],
    dtype={'x': np.float64, 'y': np.float64, 's': np.float64}
)

plt.plot(readfile['x'], readfile['y'] ,label='Hake RyR efflux',color='red')
plt.show()

Successful plot

prefix_file='~/Desktop/'
file_name='Rep01_Cys239SG_ligandF1_dist.dat'

# plot a file (standalone from dataset)
filename=prefix_file + file_name
readfile= pd.read_csv(
    filename,
    delimiter=' ',
    names=['s1','s2','s3','s4','s5','s6','s7','x','s8','s9','s10','s11','s12', 'y'],
    dtype={'x': np.float64, 'y': np.float64}    
)

plt.plot(readfile['x'], readfile['y'] ,label='Hake RyR efflux',color='blue')
plt.show()

Unsuccessful plot

Example of first 20 lines of Ca_sr.World.avg_stddev.dat:

0 11795 0
1e-05 11941.56 73.400861030372
2e-05 12063 60.216276869298
3e-05 12089.76 80.550247671872
4e-05 12117.32 84.542401196086
5e-05 12138.96 81.17018171718
6e-05 12182.64 63.665299810807
7e-05 12148.24 73.5615551766
8e-05 12168.32 74.333690881053
9e-05 12161.12 85.144733248745
0.0001 12165.88 64.499500773262
0.00011 12190.88 76.538784939402
0.00012 12180.44 68.184502638063
0.00013 12190.72 62.885623158239
0.00014 12174.16 85.336829095063
0.00015 12175.36 58.05024030958
0.00016 12187.4 70.30163582734
0.00017 12209.36 69.206866711331
0.00018 12186.84 70.809423101731
0.00019 12212.04 82.26857480229

Example of first 20 lines of Rep01_Cys239SG_ligandF1_dist.dat:

#Frame      Dis_00003
       1      12.0948
       2      11.8884
       3      11.8573
       4      11.8988
       5      12.0257
       6      10.8092
       7      10.6126
       8      10.6221
       9      10.6896
      10      10.5544
      11      10.0383
      12      10.5199
      13      10.0731
      14      10.6336
      15      10.6044
      16       9.9472
      17      10.2276
      18       9.9793
      19      10.4104

UPDATE

This definitely has something to do with the way I am hardcoding the lines into the names value. In short, I need a way to ignore all the NaN (space) values and process only the floats.

See the following image of the data description Data description :

0 Answers
Related