Skip to content Skip to sidebar Skip to footer

3d Plot Of List Of (hist, Bin_edges) Where Histogram Bar Chart Or Lines Are In The Z-y Plane

EDIT - reworked question I need to print a 3D histogram of fitness data for 50 generations of computer programmes. This data is in calculated and stored in a logbook using the DEA

Solution 1:

I use mplot3d and bar to plot 3d-hist as follow:

enter image description here


#!/usr/bin/python3
# 2017.12.31 18:46:42 CST
# 2017.12.31 19:23:51 CST
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

## the hist data
data = np.array([
        np.array([826, 145,  26,   2,   1,   0,   0,   0,   0,   0]),
        np.array([389, 446, 145,  16,   4,   0,   0,   0,   0,   0]),
        np.array([227, 320, 368,  73,  12,   0,   0,   0,   0,   0]),
        np.array([199, 128, 369, 261,  43,   0,   0,   0,   0,   0]),
        np.array([219,  92, 158, 393, 137,   1,   0,   0,   0,   0]),
        np.array([252,  90,  91, 237, 323,   6,   1,   0,   0,   0]),
        np.array([235,  89,  69,  96, 470,  36,   5,   0,   0,   0]),
        np.array([242,  78,  61,  51, 438, 114,  16,   0,   0,   0]),
        np.array([235,  82,  52,  52, 243, 279,  57,   0,   0,   0])
        ])

## other data 
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
colors = ["r","g","b"]*10

## Draw 3D hist 
ncnt, nbins = data.shape[:2]
xs = np.arange(nbins)
for i in range(ncnt):
    ys = data[i]
    cs = [colors[i]] * nbins
    ax.bar(xs, ys.ravel(), zs=i, zdir='x', color=cs, alpha=0.8)

ax.set_xlabel('idx')
ax.set_ylabel('bins')
ax.set_zlabel('nums')
plt.show()

Post a Comment for "3d Plot Of List Of (hist, Bin_edges) Where Histogram Bar Chart Or Lines Are In The Z-y Plane"