Reputation: 481
I'm having a very weird behavior in matplotlib+seaborn.
Please, never mind aesthetic features!
I have a .csv file which rows have very small values
The read of csv is with pandas:
csvdata = pd.read_csv('csv.csv', sep=';', header=None, index_col=0)
idx = np.arange(1, 33)
y = csvdata.iloc[4,idx]
x = csvdata.iloc[0,idx]
Each line of that file is my 'y', and has values as:
0.000001479;0.000001562;1.47E-06;1.39E-06;1.35E-06;1.36E-06;1.33E-06;1.30E-06;1.25E-06;1.26E-06;0.000001249;1.23E-06;1.21E-06;1.19E-06;1.17E-06;1.18E-06;1.17E-06;1.12E-06;1.11E-06;1.10E-06;1.11E-06;1.10E-06;0.000001073;0.000001055;1.05E-06;1.05E-06;1.03E-06;1.02E-06;1.02E-06;1.01E-06;1.01E-06;1.01E-06
An the 'x' is:
0.223214286;0.446428571;0.669642857;1;1;1;2;2;2;2;2;3;3;3;3;4;4;4;4;4;5;5;5;5;6;6;6;6;6;7;7;7
When I try to plot that row in matplotlib, it gives me:
As one can see, the plot is grouping a lot of values. I tried to set the xaxis values in order to make it corret, so I did:
fig = sb.plt.figure(figsize=(12, 5))
ax = fig.add_subplot(111)
ax.plot(x, y, '-o', color='orange', linewidth=3)
fmt = tkr.FormatStrFormatter('%1.1E')
ax.yaxis.set_major_formatter(fmt)
fmt = tkr.FormatStrFormatter('%1.2f')
ax.xaxis.set_major_formatter(fmt)
ax.xaxis.set_major_locator(tkr.MultipleLocator(.22))
And the result:
And what I want is (exported from Excel):
Any idea of whats is causing this problem? In my opinion, it shold be as simple as: plot(x,y) and the matplotlib should identify all values in both axis...
Did I miss something?
In advance, thank you all!
Upvotes: 1
Views: 701
Reputation: 481
After some suggestions of @tom and @tmoreau, I saw that problem was on the values o x!
Thank you guys!
That data of csv is exported from excel and if the "Number format" there doesnt have precision, it will export the data as truncated values!
After the fix, I have the x values:
0.22321428571428600000;0.44642857142857100000;0.66964285714285700000;0.89285714285714300000;1.11607142857143000000;1.33928571428571000000;1.56250000000000000000;1.78571428571429000000;2.00892857142857000000;2.23214285714286000000;2.45535714285714000000;2.67857142857143000000;2.90178571428571000000;3.12500000000000000000;3.34821428571428000000;3.57142857142857000000;3.79464285714286000000;4.01785714285714000000;4.24107142857143000000;4.46428571428571000000;4.68750000000000000000;4.91071428571428000000;5.13392857142857000000;5.35714285714286000000;5.58035714285714000000;5.80357142857143000000;6.02678571428571000000;6.25000000000000000000;6.47321428571428000000;6.69642857142857000000;6.91964285714285000000;7.14285714285714000000
And the ploting works like a charm:
Upvotes: 1