0

I was reproducing results from a paper and I came across this plot with these colors. I want to reproduce this plot, but I could not figure out how.

enter image description here

Here is my current code:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.array(range(0, 16), float)
y = x.copy()
xpos, ypos = np.meshgrid(x, y)
z = np.array(m).reshape(-1)
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros_like(xpos)
dx = 0.75 * np.ones_like(zpos)
dy = dx.copy()
dz = z.flatten() # This is the actual data.
fig = plt.figure()
ax = fig.add_subplot(111,projection = '3d')
ax.bar3d(xpos, ypos, zpos, dx, dy, dz,
     shade=True
        )
title = titles[t]
t += 1
ax.title.set_text(r"{w}".format(w=title))
plt.show()

which outputs the following plot:

enter image description here

What parameters should I add/change to make it look like the plot from the paper?

tdy
  • 36,675
  • 19
  • 86
  • 83
Dimitri
  • 109
  • 1
  • 14

1 Answers1

0

Pulling from a few other answers like here and here, this should get you closer to that figure

import numpy as np
import matplotlib.pyplot as plt

## Test data
m = np.random.rand(16,16)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.array(range(0, 16), float)
y = x.copy()
xpos, ypos = np.meshgrid(x, y)
z = np.array(m).reshape(-1)
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros_like(xpos)
dx = 0.75 * np.ones_like(zpos)
dy = dx.copy()
dz = z.flatten()

## Define a colorbar
cmap = plt.cm.get_cmap('hsv')
max_height = m.max()
min_height = m.min()
color_values = [cmap((i-min_height)/max_height) for i in dz]

## 3D Bar Plot
bar = ax.bar3d(xpos, ypos, zpos, dx, dy, dz,
     shade=True, color=color_values)

## Colorbar
cbar_obj = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(min_height, max_height))
cbar_obj.set_array([dz])
cbar = plt.colorbar(cbar_obj)

plt.show()

enter image description here

astroChance
  • 337
  • 1
  • 10