Python Forum
[pandas, plot] : complex bug - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: [pandas, plot] : complex bug (/thread-3857.html)



[pandas, plot] : complex bug - membreComplexe12 - Jun-30-2017

Hello,

first of all, sorry for my english..

I write to you because a have a very strange problem and I can't solve it by myself, please could you give me your help ?

This is the summary of my code :
1) I read data from an excel file
2) I put these data in two "dataframe" thanks to panda
3) I select a value for the variable "p" in order to select either the dataframe 0 or the number 1
4) I plot in 2D the "fx, fy et fz" variables
5) I plot in 3D the "fx, fy et fz" variables

my bug
the 2D plot is nice for the dataframe p=0 and for p=1.
But, there is a bug in the 3D plotting because when my variable p is equal to one I have an error message very strange (cf. below)

I don't understand because if I can plot my "fx, fy et fz" data in 2D, I should plot it in 3D also.... ?

I hope that you will help me because it is an important issue for me.

Thanks a lot

import sys
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#for jupiter
from IPython import display 
#for 3D plot
from mpl_toolkits.mplot3d import Axes3D
############# OK ###############
fpath = './test.xlsx'
df = pd.read_excel(fpath, sheetname='bilan', skiprows=1,convert_float='False')
dfLabo=df.iloc[:,0:8]
columnsInteret=['a','b','c','d','f','g']
dfLabo_F1=dfLabo.loc[0:9,columnsInteret]
dfLabo_F2=dfLabo.loc[10:19,columnsInteret]
dataFramePlot=[dfLabo_F1,dfLabo_F2]
############# PLOT 2D: OK ###############
p=1
fx = dataFramePlot[p].loc[:,'a']
fy = dataFramePlot[p].loc[:,'b']
fz = dataFramePlot[p].loc[:,'f']
fig = plt.figure("2D")
ax = fig.add_subplot(111)
ax.plot(fx, fy,linestyle="None",marker="o")
ax.plot(fy, fz,linestyle="None",marker="o")
ax.plot(fx, fz,linestyle="None",marker="o")
plt.show()
############# PLOT 3D: BUG ###############
fig3D = plt.figure("3D")
ax3D = fig3D.add_subplot(111, projection='3d')
ax3D.plot(fx, fy, fz,linestyle="None",marker="o")
plt.show()
The error message Evil Angry
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-176-277be64011bc> in <module>() 1 fig3D = plt.figure("3D") 2 ax3D = fig3D.add_subplot(111, projection='3d') ----> 3ax3D.plot(fx, fy, fz,linestyle="None",marker="o") 4 plt.show() C:\Users\localApps\Anaconda35\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in plot(self, xs, ys, *args, **kwargs) 1526 # Next, check to see if the data contained 1527 # therein (if any) is scalar (and not another array). -> 1528 if len(args[0]) == 0 or cbook.is_scalar(args[0][0]) : 1529 zs = args[argsi] 1530 argsi += 1 C:\Users\localApps\Anaconda35\lib\site-packages\pandas\core\series.py in __getitem__(self, key) 599 key = com._apply_if_callable(key, self) 600 try: --> 601result = self.index.get_value(self, key) 602 603 if not is_scalar(result): C:\Users\localApps\Anaconda35\lib\site-packages\pandas\indexes\base.py in get_value(self, series, key) 2167 try: 2168 return self._engine.get_value(s, k, -> 2169 tz=getattr(series.dtype, 'tz', None)) 2170 except KeyError as e1: 2171 if len(self) > 0 and self.inferred_type in ['integer', 'boolean']: pandas\index.pyx in pandas.index.IndexEngine.get_value (pandas\index.c:3567)() pandas\index.pyx in pandas.index.IndexEngine.get_value (pandas\index.c:3250)() pandas\index.pyx in pandas.index.IndexEngine.get_loc (pandas\index.c:4289)() pandas\src\hashtable_class_helper.pxi in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:8555)() pandas\src\hashtable_class_helper.pxi in pandas.hashtable.Int64HashTable.get_item (pandas\hashtable.c:8499)() KeyError: 0