Issue
I want to generate a heatcube. The axis are specific values for 3 different parameters and the actual value of a point (x,y,z)
is a goodness of fit value. That means (x,y,z)
should be read as categorical variables. However, I struggle to get the axis on the right scale so that it only considers the given values to be plotted and not a continuum of points
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
lam = [0.000001, 0.00001, 0.0001, 0.001, 0.01, 1, 10]
alpha = [0.0001, 0.001, 0.01, 0.02, 0.03, 0.04, 0.05, 0.1, 0.2]
delta = [0, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 1, 10]
X, Y, Z = np.meshgrid(lam, alpha, delta)
c = np.random.randn(len(lam), len(alpha), len(delta))
ax.scatter(X,Y,Z, c=c,cmap="brg")
plt.show()
which gives a misleading picture:
As one can see the plot has by far too large spaces on the different axis. I would like to have only points shown the actual values of lam
, alpha
, delta
like in this plot
Solution
You need to set_{}ticks
for ax:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
lam = [0.000001, 0.00001, 0.0001, 0.001, 0.01, 1, 10]
alpha = [0.0001, 0.001, 0.01, 0.02, 0.03, 0.04, 0.05, 0.1, 0.2]
delta = [0, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 1, 10]
X, Y, Z = np.meshgrid(lam, alpha, delta)
c = np.random.randn(len(lam), len(alpha), len(delta))
ax.scatter(X, Y, Z, c=c, cmap="brg",)
ax.set_xticks(lam)
ax.set_yticks(alpha)
ax.set_zticks(delta)
plt.show()
It does not look good though, because you have no logarithmic scale:
Better solution (maybe thats what you wanted after all) is to make meshgrid of indices and substitute labels of ticks:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
lam = [0.000001, 0.00001, 0.0001, 0.001, 0.01, 1, 10]
alpha = [0.0001, 0.001, 0.01, 0.02, 0.03, 0.04, 0.05, 0.1, 0.2]
delta = [0, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 1, 10]
# X, Y, Z = np.meshgrid(lam, alpha, delta)
X, Y, Z = np.meshgrid(np.arange(len(lam)), np.arange(len(alpha)), np.arange(len(delta)))
c = np.random.randn(len(lam), len(alpha), len(delta))
ax.scatter(X, Y, Z, c=c, cmap="brg",)
ax.set_xticklabels(lam)
ax.set_yticklabels(alpha)
ax.set_zticklabels(delta)
plt.show()
Answered By - dankal444
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.