Skip to content

Instantly share code, notes, and snippets.

@marekyggdrasil
Last active December 2, 2019 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marekyggdrasil/f324e8bc653896a5e1bccbef4d31e0e8 to your computer and use it in GitHub Desktop.
Save marekyggdrasil/f324e8bc653896a5e1bccbef4d31e0e8 to your computer and use it in GitHub Desktop.
Inconsistent Matplotlib behaviour, running script multiple times leads to different outcomes. Posted as question on StackOverflow under URL: https://stackoverflow.com/questions/59101292/matplotlib-randomly-ignored-passed-parameters-at-each-execution
import numpy as np
import sys
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from mpl_toolkits.mplot3d import Axes3D
gs = gridspec.GridSpec(1, 2)
fig = plt.figure()
fig.suptitle('plotting test')
axes_real = fig.add_subplot(gs[0, 0], projection='3d')
axes_imag = fig.add_subplot(gs[0, 1], projection='3d')
rho = np.array([[0.3+0.2j, 0.2+0.1j], [0.2-0.1j, 0.3]])
rho_ref = np.array([[0.35+0.15j, 0.25+0.15j], [0.15-0.15j, 0.35]])
s = 0.1
sm = 0.5*s
alpha_mes = 0.40
alpha_ref = 0.1
for axes, M, M_ref in zip([axes_real, axes_imag], [rho.real, rho.imag], [rho_ref.real, rho_ref.imag]):
axes.set_zlim(-1., 1.)
axes.set_xticks([0.5, 1.5])
axes.set_xticklabels(['$a$', '$b$'])
axes.set_yticks([0.5, 1.5])
axes.set_yticklabels(['$a$', '$b$'])
axes.set_aspect(1.0)
axes.bar3d(
sm, sm, 0., 1.-s, 1.-s, M[0, 0],
color='blue',
alpha=alpha_mes,
zsort='average')
axes.bar3d(
0., 0., 0., 1., 1., M_ref[0, 0],
color='white',
alpha=alpha_ref,
zsort='average',
edgecolor='black')
axes.bar3d(
1.+sm, sm, 0., 1.-s, 1.-s, 1.0,
color='blue',
alpha=alpha_mes,
zsort='average')
axes.bar3d(
1., 0., 0., 1., 1., M_ref[0, 0],
color='white',
alpha=alpha_ref,
zsort='average',
edgecolor='black')
axes.bar3d(
sm, 1.+sm, 0, 1.-s, 1.-s, 1.0,
color='blue',
alpha=alpha_mes,
zsort='average')
axes.bar3d(
0., 1., 0., 1., 1., M_ref[0, 0],
color='white',
alpha=alpha_ref,
zsort='average',
edgecolor='black')
axes.bar3d(
1.+sm, 1.+sm, 0., 1.-s, 1.-s, M[0, 0],
color='blue',
alpha=alpha_mes,
zsort='average')
axes.bar3d(
1., 1., 0., 1., 1., M_ref[0, 0],
color='white',
alpha=alpha_ref,
zsort='average',
edgecolor='black')
axes_real.view_init(elev=25., azim=45)
axes_imag.view_init(elev=25., azim=45)
# plt.show()
fig.savefig('plot_file_'+sys.argv[1]+'.png')
@marekyggdrasil
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment