I wanted to explore the possibility of creating 3-Dimensional plots so that I can include some in my PhD thesis. This ended up being a lot more work than I thought and not just because i got stuck in the aesthetics. The bottleneck I have encountered came from simultaneously sifting through the official documentation, looking at endless questions on stack overflow and trawling through personal blogs.

Here is the code that I have used to generate the surface plot above:

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

from matplotlib import cm, rc

def fun(x,y):

return(-4*np.pi*(x/y)*np.log(x/(x+y)))

x = y = np.arange(0.1,50,0.1)

fig = plt.figure(dpi=300)

ax1 = fig.gca(projection='3d')

X, Y = np.meshgrid(x,y)

mu_sigma = np.array([fun(x,y) for x,y in zip(X, Y)])

Z = mu_sigma.reshape(X.shape)

surf = ax1.plot_surface(Y, X, Z, rstride=10, cstride=10, linewidth=0.,

cmap=cm.jet, antialiased=False)

ax1.grid(False)

ax1.xaxis.pane.set_edgecolor('white')

ax1.yaxis.pane.set_edgecolor('white')

ax1.zaxis.pane.set_edgecolor('white')

ax1.xaxis.pane.fill = False

ax1.yaxis.pane.fill = False

ax1.zaxis.pane.fill = False

ax1.view_init(elev=15, azim=315)

ax1.set_xlabel(r'$\Delta R$', fontsize=16)

ax1.set_ylabel(r'$R_\mathrm{in}$',fontsize=16)

ax1.xaxis.set_rotate_label(False)

ax1.yaxis.set_rotate_label(False)

for i in ax1.axes.get_zticklabels():

i.set_visible(False)

[t.set_va('center') for t in ax1.get_yticklabels()]

[t.set_ha('left') for t in ax1.get_yticklabels()]

[t.set_va('center') for t in ax1.get_xticklabels()]

[t.set_ha('right') for t in ax1.get_xticklabels()]

cbar = fig.colorbar(surf, shrink=0.75, ticks=[0.5,12.5], orientation='horizontal')

#cbar = fig.colorbar(surf, shrink=0.5, aspect=10, ticks=[0.5,12.5], orientation='vertical')

cbar.ax.set_xticklabels(['0','4$\pi$'])

cbar.ax.tick_params(labelsize=16)

Having played around with the grid across the surface I decided on something with fairly large segments.

The colour bar also took some playing with in order to get the labels to match up with the limits of the equation. A horizontal bar underneath looked much better than a vertical bar down the side