Question:
How to create a 3D fill-between plot from an array?

Problem:

I have a 3D matrix from simulating four random variables during 6 hours 2000 times.

# Display the shape of the matrix_outputs array

print(matrix_outputs.shape)

(2000, 86400, 4)


The first term is the number of running from the simulation, the second term is the number of samples, and the last one is the number of variables generated (estimated load, estimated energy to harvest, real load, and real renewable harvested).


Plotting the first run I have:


The code I used for plotting it:


# Define time

import matplotlib.pyplot as plt

t = np.arange(0, max_sim/(60/0.25), 1/(60/0.25))  # Define time in minutes using the 'max_sim'

    

# Create a plot

fig, ax = plt.subplots(1)

fig.set_size_inches(10, 5)

ax.fill_between(t, matrix_outputs[0,:,0], facecolor='C0', alpha=0.4)

ax.fill_between(t, matrix_outputs[0,:,1], facecolor='C1', alpha=0.4)ax.fill_between(t, matrix_outputs[0,:,2], facecolor='C2', alpha=0.4)

ax.fill_between(t, matrix_outputs[0,:,3], facecolor='C3', alpha=0.4)


I want to plot something as the following image:


With the axis to be:


So far I have

# Define time

t = np.arange(0, max_sim/(60/0.25), 1/(60/0.25))  # Define time in minutes using the 'max_sim'


# Create a 3D plot

fig = plt.figure()

ax = fig.add_subplot(projection='3d')


# Set labels for the axes

ax.set_xlabel('Time (minutes)')  # Set the x-axis label to represent time

ax.set_ylabel('Run ID')

ax.set_zlabel('Random Variable Output')


# Plot the data points using time 't', number run, and random outputs

ax.plot(t, matrix_outputs[0,:,0], matrix_outputs[:,0,0],zdir='y')


# Show the plot

plt.show()


But I don't know how to implement each number to make a 3D plot. Thank you for any advice!


Solution:


Try this sample to create your 3D chart.


import matplotlib.pyplot as plt import numpy as np fig = plt.figure(figsize=(20, 10)) axl = fig.add_subplot(projection='3d') for z in np.arange(0, 40, 10): x = np.arange(20) y = np.random.randn(20) axl.bar(x, y, zs=z, zdir='y') axl.set_xlabel('x', fontsize=15) axl.set_ylabel('y', fontsize=15) axl.set_zlabel('z', fontsize=15) plt.show()


Suggested blogs:

>Fix ASP.NET Core Model Binding Not Working issue.

>How to create a zip file and return it to client for download?

>How to Group large number of data based on CreatedDate(DateTime)?

>Issues converting ASPX Web app from .net 3.5 to 4.8.1

>Fix Asp.net issue: AjaxControlToolkit FileUpload not working

>Using Fetch in JS to call a server-side method (ASP.NET)

>Need input on Standalone SSRS SQL Server 2016 Report Builder

>How to fix: View not found even though it exists issue?

>Fixing C# sync over async implementations

>How to optimize getting multiple documents 'one by one' in Firestore?

>How to use/set up Node Express sessions?


Ritu Singh

Ritu Singh

Submit
0 Answers