owais ahmed
Student
- Nov 10, 2021
- 10
I want to plot 4 dimensional graph by using the following code in python matplotlib but i am getting this error
index 10 is out of bounds for axis 0 with size 4
how could i resolve this issue? please comment
```import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# create some fake data
x =np.array([-0.256000000000000,
-0.173400000000001,
-0.108800000000002,
-0.0578000000000003,
-0.0194000000000010,
0.0103000000000009,
0.0317000000000007,
0.0502000000000002,
0.0655000000000001,
0.0763999999999996,
0.0816000000000017,
0.0794999999999995,
0.0704999999999991,
0.0647000000000020,
0.0679000000000016,
0.0753999999999984,
0.0843999999999987,
0.0978999999999992,
0.100500000000000,
0.0792999999999999,
0.0505999999999993,
0.0339999999999989,
0.0429999999999993,
0.0628000000000029,
0.0565999999999995,
0.00840000000000174,
-0.0280000000000022,
-0.00930000000000320,
0.0268000000000015,
0.0444999999999993,
0.0509999999999984,
0.0536999999999992,
0.0427999999999997,
0.0106000000000002,
-0.0335999999999999,
-0.0593000000000004,
-0.0457999999999998,
-0.0149999999999988,
0.0149999999999988,
0.0457999999999998,
0.0593000000000004,
0.0335999999999999,
-0.0106000000000002,
-0.0427999999999997,
-0.0536999999999992,
-0.0510000000000002,
-0.0445000000000011,
-0.0267999999999997,
0.00929999999999964,
0.0280000000000005,
-0.00839999999999996,
-0.0566000000000013,
-0.0627999999999993,
-0.0430000000000010,
-0.0339999999999989,
-0.0505999999999993,
-0.0792999999999999,
-0.100500000000000,
-0.0979000000000010,
-0.0842999999999989,
-0.0754000000000001,
-0.0678999999999999,
-0.0647000000000002,
-0.0705100000000005,
-0.0795099999999991,
-0.0815800000000007,
-0.0763700000000007,
-0.0655400000000004,
-0.0501600000000000,
-0.0316599999999987,
-0.0102799999999998,
0.0193599999999989,
0.0578400000000006,
0.108800000000000,
0.173390000000000,
0.256040000000000])
y=np.array([0.120020800000000,
0.117440400000000,
0.118825300000000,
0.121856900000000,
0.119601200000000,
0.113767300000000,
0.121083600000000,
0.117765400000000,
0.118545800000000,
0.117321300000000,
0.119664500000000,
0.119432800000000,
0.116053900000000,
0.121967400000000,
0.113445900000000,
0.120177500000000,
0.116851600000000,
0.118181000000000,
0.116287000000000,
0.119227000000000,
0.116636200000000,
0.117706800000000,
0.117595800000000,
0.116112400000000,
0.117493300000000,
0.116921500000000,
0.117896600000000,
0.114317800000000,
0.118866100000000,
0.114900400000000,
0.117458900000000,
0.114476700000000,
0.117961800000000,
0.114764700000000,
0.117575000000000,
0.115172600000000,
0.115895100000000,
0.116212200000000,
0.116212300000000,
0.115895100000000,
0.115172600000000,
0.117575000000000,
0.114764700000000,
0.117961900000000,
0.114476800000000,
0.117458900000000,
0.114900400000000,
0.118866300000000,
0.114317700000000,
0.117896700000000,
0.116921500000000,
0.117493400000000,
0.116112300000000,
0.117595800000000,
0.117706800000000,
0.116636200000000,
0.119227000000000,
0.116287000000000,
0.118180900000000,
0.116851600000000,
0.120177300000000,
0.113446000000000,
0.121967200000000,
0.116053800000000,
0.119432800000000,
0.119664300000000,
0.117321100000000,
0.118545500000000,
0.117765000000000,
0.121082900000000,
0.113766800000000,
0.119600300000000,
0.121855600000000,
0.118823400000000,
0.117437800000000,
0.120017800000000])
# here are the x,y and respective z values
X, Y = np.meshgrid(x, y)
Z = np.array([0.256010000000000,
0.316988000000000,
0.412030000000000,
0.516346000000000,
0.626786000000000,
0.741815000000000,
0.860470000000000,
0.978995000000000,
1.09728000000000,
1.22166000000000,
1.34358000000000,
1.46219000000000,
1.56897000000000,
1.65295000000000,
1.73330000000000,
1.81729000000000,
1.90177000000000,
1.99564000000000,
2.10919000000000,
2.21172000000000,
2.28187000000000,
2.32508000000000,
2.36278000000000,
2.43046000000000,
2.52447000000000,
2.58640000000000,
2.56648000000000,
2.54086000000000,
2.56341000000000,
2.61716000000000,
2.67098000000000,
2.72803000000000,
2.78671000000000,
2.82788000000000,
2.82644000000000,
2.77211000000000,
2.71099000000000,
2.68332000000000,
2.68332000000000,
2.71099000000000,
2.77210000000000,
2.82643000000000,
2.82788000000000,
2.78670000000000,
2.72802000000000,
2.67097000000000,
2.61715000000000,
2.56340000000000,
2.54085000000000,
2.56647000000000,
2.58639000000000,
2.52445000000000,
2.43045000000000,
2.36276000000000,
2.32507000000000,
2.28185000000000,
2.21171000000000,
2.10918000000000,
1.99563000000000,
1.90176000000000,
1.81728000000000,
1.73330000000000,
1.65295000000000,
1.56897000000000,
1.46219000000000,
1.34358000000000,
1.22166000000000,
1.09728000000000,
0.978995000000000,
0.860470000000000,
0.741815000000000,
0.626785000000000,
0.516343000000000,
0.412026000000000,
0.316984000000000,
0.256005000000000
])
# this is the value to use for the color
V = np.array([35.4849000000000,
35.8240000000000,
35.8697000000000,
35.3643000000000,
34.6013000000000,
34.2768000000000,
33.9248000000000,
33.7202000000000,
33.6194000000000,
33.5584000000000,
33.4524000000000,
33.3797000000000,
33.2483000000000,
33.1658000000000,
33.1662000000000,
33.1639000000000,
33.1750000000000,
33.2539000000000,
33.2556000000000,
33.1561000000000,
33.0730000000000,
33.0314000000000,
33.1068000000000,
33.2449000000000,
33.2210000000000,
33.1155000000000,
33.1342000000000,
33.1272000000000,
33.1793000000000,
33.1467000000000,
33.1168000000000,
33.1148000000000,
33.1004000000000,
33.0870000000000,
33.0951000000000,
33.1944000000000,
33.2195000000000,
33.1563000000000,
33.1562000000000,
33.2194000000000,
33.1944000000000,
33.0951000000000,
33.0869000000000,
33.1004000000000,
33.1148000000000,
33.1168000000000,
33.1467000000000,
33.1793000000000,
33.1272000000000,
33.1342000000000,
33.1155000000000,
33.2210000000000,
33.2449000000000,
33.1068000000000,
33.0314000000000,
33.0730000000000,
33.1561000000000,
33.2556000000000,
33.2539000000000,
33.1749000000000,
33.1639000000000,
33.1662000000000,
33.1658000000000,
33.2483000000000,
33.3797000000000,
33.4524000000000,
33.5584000000000,
33.6194000000000,
33.7204000000000,
33.9244000000000,
34.2766000000000,
34.6038000000000,
35.3626000000000,
35.8694000000000,
35.8238000000000,
35.4848000000000])
# create the figure, add a 3d axis, set the viewing angle
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.view_init(100,600)
# here we create the surface plot, but pass V through a colormap
# to create a different color for each patch
ax.plot_surface(X, Y, Z, facecolors=cm.Oranges(V))
```
??
index 10 is out of bounds for axis 0 with size 4
how could i resolve this issue? please comment
```import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# create some fake data
x =np.array([-0.256000000000000,
-0.173400000000001,
-0.108800000000002,
-0.0578000000000003,
-0.0194000000000010,
0.0103000000000009,
0.0317000000000007,
0.0502000000000002,
0.0655000000000001,
0.0763999999999996,
0.0816000000000017,
0.0794999999999995,
0.0704999999999991,
0.0647000000000020,
0.0679000000000016,
0.0753999999999984,
0.0843999999999987,
0.0978999999999992,
0.100500000000000,
0.0792999999999999,
0.0505999999999993,
0.0339999999999989,
0.0429999999999993,
0.0628000000000029,
0.0565999999999995,
0.00840000000000174,
-0.0280000000000022,
-0.00930000000000320,
0.0268000000000015,
0.0444999999999993,
0.0509999999999984,
0.0536999999999992,
0.0427999999999997,
0.0106000000000002,
-0.0335999999999999,
-0.0593000000000004,
-0.0457999999999998,
-0.0149999999999988,
0.0149999999999988,
0.0457999999999998,
0.0593000000000004,
0.0335999999999999,
-0.0106000000000002,
-0.0427999999999997,
-0.0536999999999992,
-0.0510000000000002,
-0.0445000000000011,
-0.0267999999999997,
0.00929999999999964,
0.0280000000000005,
-0.00839999999999996,
-0.0566000000000013,
-0.0627999999999993,
-0.0430000000000010,
-0.0339999999999989,
-0.0505999999999993,
-0.0792999999999999,
-0.100500000000000,
-0.0979000000000010,
-0.0842999999999989,
-0.0754000000000001,
-0.0678999999999999,
-0.0647000000000002,
-0.0705100000000005,
-0.0795099999999991,
-0.0815800000000007,
-0.0763700000000007,
-0.0655400000000004,
-0.0501600000000000,
-0.0316599999999987,
-0.0102799999999998,
0.0193599999999989,
0.0578400000000006,
0.108800000000000,
0.173390000000000,
0.256040000000000])
y=np.array([0.120020800000000,
0.117440400000000,
0.118825300000000,
0.121856900000000,
0.119601200000000,
0.113767300000000,
0.121083600000000,
0.117765400000000,
0.118545800000000,
0.117321300000000,
0.119664500000000,
0.119432800000000,
0.116053900000000,
0.121967400000000,
0.113445900000000,
0.120177500000000,
0.116851600000000,
0.118181000000000,
0.116287000000000,
0.119227000000000,
0.116636200000000,
0.117706800000000,
0.117595800000000,
0.116112400000000,
0.117493300000000,
0.116921500000000,
0.117896600000000,
0.114317800000000,
0.118866100000000,
0.114900400000000,
0.117458900000000,
0.114476700000000,
0.117961800000000,
0.114764700000000,
0.117575000000000,
0.115172600000000,
0.115895100000000,
0.116212200000000,
0.116212300000000,
0.115895100000000,
0.115172600000000,
0.117575000000000,
0.114764700000000,
0.117961900000000,
0.114476800000000,
0.117458900000000,
0.114900400000000,
0.118866300000000,
0.114317700000000,
0.117896700000000,
0.116921500000000,
0.117493400000000,
0.116112300000000,
0.117595800000000,
0.117706800000000,
0.116636200000000,
0.119227000000000,
0.116287000000000,
0.118180900000000,
0.116851600000000,
0.120177300000000,
0.113446000000000,
0.121967200000000,
0.116053800000000,
0.119432800000000,
0.119664300000000,
0.117321100000000,
0.118545500000000,
0.117765000000000,
0.121082900000000,
0.113766800000000,
0.119600300000000,
0.121855600000000,
0.118823400000000,
0.117437800000000,
0.120017800000000])
# here are the x,y and respective z values
X, Y = np.meshgrid(x, y)
Z = np.array([0.256010000000000,
0.316988000000000,
0.412030000000000,
0.516346000000000,
0.626786000000000,
0.741815000000000,
0.860470000000000,
0.978995000000000,
1.09728000000000,
1.22166000000000,
1.34358000000000,
1.46219000000000,
1.56897000000000,
1.65295000000000,
1.73330000000000,
1.81729000000000,
1.90177000000000,
1.99564000000000,
2.10919000000000,
2.21172000000000,
2.28187000000000,
2.32508000000000,
2.36278000000000,
2.43046000000000,
2.52447000000000,
2.58640000000000,
2.56648000000000,
2.54086000000000,
2.56341000000000,
2.61716000000000,
2.67098000000000,
2.72803000000000,
2.78671000000000,
2.82788000000000,
2.82644000000000,
2.77211000000000,
2.71099000000000,
2.68332000000000,
2.68332000000000,
2.71099000000000,
2.77210000000000,
2.82643000000000,
2.82788000000000,
2.78670000000000,
2.72802000000000,
2.67097000000000,
2.61715000000000,
2.56340000000000,
2.54085000000000,
2.56647000000000,
2.58639000000000,
2.52445000000000,
2.43045000000000,
2.36276000000000,
2.32507000000000,
2.28185000000000,
2.21171000000000,
2.10918000000000,
1.99563000000000,
1.90176000000000,
1.81728000000000,
1.73330000000000,
1.65295000000000,
1.56897000000000,
1.46219000000000,
1.34358000000000,
1.22166000000000,
1.09728000000000,
0.978995000000000,
0.860470000000000,
0.741815000000000,
0.626785000000000,
0.516343000000000,
0.412026000000000,
0.316984000000000,
0.256005000000000
])
# this is the value to use for the color
V = np.array([35.4849000000000,
35.8240000000000,
35.8697000000000,
35.3643000000000,
34.6013000000000,
34.2768000000000,
33.9248000000000,
33.7202000000000,
33.6194000000000,
33.5584000000000,
33.4524000000000,
33.3797000000000,
33.2483000000000,
33.1658000000000,
33.1662000000000,
33.1639000000000,
33.1750000000000,
33.2539000000000,
33.2556000000000,
33.1561000000000,
33.0730000000000,
33.0314000000000,
33.1068000000000,
33.2449000000000,
33.2210000000000,
33.1155000000000,
33.1342000000000,
33.1272000000000,
33.1793000000000,
33.1467000000000,
33.1168000000000,
33.1148000000000,
33.1004000000000,
33.0870000000000,
33.0951000000000,
33.1944000000000,
33.2195000000000,
33.1563000000000,
33.1562000000000,
33.2194000000000,
33.1944000000000,
33.0951000000000,
33.0869000000000,
33.1004000000000,
33.1148000000000,
33.1168000000000,
33.1467000000000,
33.1793000000000,
33.1272000000000,
33.1342000000000,
33.1155000000000,
33.2210000000000,
33.2449000000000,
33.1068000000000,
33.0314000000000,
33.0730000000000,
33.1561000000000,
33.2556000000000,
33.2539000000000,
33.1749000000000,
33.1639000000000,
33.1662000000000,
33.1658000000000,
33.2483000000000,
33.3797000000000,
33.4524000000000,
33.5584000000000,
33.6194000000000,
33.7204000000000,
33.9244000000000,
34.2766000000000,
34.6038000000000,
35.3626000000000,
35.8694000000000,
35.8238000000000,
35.4848000000000])
# create the figure, add a 3d axis, set the viewing angle
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.view_init(100,600)
# here we create the surface plot, but pass V through a colormap
# to create a different color for each patch
ax.plot_surface(X, Y, Z, facecolors=cm.Oranges(V))
```
??