"""
To generate the figure, run this script.
For better margin, chance the resulting EPS bounding box parameters:
%%BoundingBox: 18 252 594 540

Make sure that the italic sans font is associated with Helvetica for 
proberly formatted labels.
"""
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np


# DM calculated from the experimental data
data_X = [0.0057, -0.0038, -0.0146, -0.0061,
          -0.0038, 0.3212, -0.4069, 0.0001,
          -0.0146, -0.4069, 0.6653, 0.0118,
          -0.0061, 0.0001, 0.0118, 0.0078]

data_Y = [0.0127, -0.0286, 0.0183, -0.0062,
          -0.028, 0.6094, -0.4642, 0.0307,
          0.0183, -0.4642, 0.3700, -0.0296,
          -0.0061, 0.0307, -0.0296, 0.0079]


labels = ['LL', 'LR', 'RL', 'RR']

# Data formatting and axis scaling.
x = np.array(range(0, 4), float)
y = x.copy()
xpos, ypos = np.meshgrid(x, y)
xpos = xpos.flatten()-.5
ypos = ypos.flatten()-.5
zpos = np.zeros_like(xpos)
dx = 0.75 * np.ones_like(zpos)
dy = dx.copy()
dz = data_X

# Generates the main figure panel
fig = plt.figure(figsize=(8, 4))

# left hand plot
ax = fig.add_subplot(121, projection='3d')
ax.view_init(azim=-30, elev=20)
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=u'r')
ax.grid()
ax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))

plt.xticks([0, 1, 2, 3], labels)
plt.yticks([0, 1, 2, 3], labels)
ax.set_zticks([-.5, 0, 0.5])
ax.set_zticklabels([-.5, 0, 0.5])
ax.set_zlim3d(-0.5, .5)
ax.text2D(0.2, 0.83, "X", transform=ax.transAxes, style='italic', size='large')
# right hand plot
dz = data_Y
ax2 = fig.add_subplot(122, projection='3d')
ax2.view_init(azim=-30, elev=20)
ax2.bar3d(xpos, ypos, zpos, dx, dy, dz, color=u'r')
ax2.grid()
ax2.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax2.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))
ax2.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 1.0))

plt.xticks([0, 1, 2, 3], labels)
plt.yticks([0, 1, 2, 3], labels)
ax2.set_zticks([-.5, 0, 0.5])
ax2.set_zticklabels([-.5, 0, 0.5])
ax2.set_zlim3d(-0.5, .5)
ax2.text2D(0.2, 0.83, 'Y', transform=ax2.transAxes, style='italic', size='large')

# Figure generation and formatting
plt.tight_layout()
plt.savefig('tomo.eps', format='eps')
plt.show()
