Sunday, 17 October 2021

Confidence Interval 3 dimensional plot

I have a 3-dimensional plot and I am able to plot it with the code written below.

Considering that my point distribution is represented by a 100x100 matrix, is it possible to plot a confidence interval on my data? In the code below, my data are called "result", while the upper bound and lower bound that I want to show are called "upper_bound" and "lower_bound".

For example, I am asking if exist something like this, but in 3 dimension (instead of 2 dimension like the picture below)

enter image description here

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter

interval = np.random.normal(0, 1, size=(100, 100))

x = np.arange(0.1,1.1,0.01)
y = np.linspace(-np.pi,np.pi,100)

X,Y = np.meshgrid(x,y)
result = []
for i,j in zip(X,Y):
    result.append(np.log(i)+np.sin(j))

upper_bound = np.array(result)+interval
lower_bound = np.array(result)-interval

fig = plt.figure()
fig.set_figwidth(20)
fig.set_figheight(6)
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, np.array(result))
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()


from Confidence Interval 3 dimensional plot

No comments:

Post a Comment