'SymmetricalLogLocator not working with Contourf in Matplotlib
I have data in which values are ranging from small negative values to positive 1000. Since the minimum and maximum differ by large scales, I first set locator as ticker.LogLocator but that masked the negative values present in the Z, left white spots in the contour. Result with LogLocator:
Then, I set the locator as ticker.SymmetricalLogLocator
, but doesn't seem to work. Below is the code:
fig, ax = plt.subplots()
zMin = np.sign(Z.min())*(np.log10(abs(ZPred.min())+1)) # Approximate for negative z minimum
a = np.logspace(zMin, np.log10(zPred.max()), levels, base = 10)
ax.contourf(X, Y, Z, a, locator = ticker.SymmetricalLogLocator(base = 10, linthresh = 0.05), cmap=cm.jet)
plt.show()
Plot obtained (Symmetrical Log Locator Result):
Even though I am assigning the levels explicitly using logspace
, it somehow assigns lot of levels to lower values and very few levels are left for higher values. Following is the value of a from numpy.logspace
:
[9.18553309e-03 1.31507595e-02 1.88277016e-02 2.69552757e-02
3.85913746e-02 5.52505644e-02 7.91012213e-02 1.13247770e-01
1.62134759e-01 2.32125365e-01 3.32329635e-01 4.75790254e-01
6.81180194e-01 9.75233210e-01 1.39622353e+00 1.99894766e+00
2.86185677e+00 4.09726793e+00 5.86598347e+00 8.39822112e+00
1.20235794e+01 1.72139385e+01 2.46448805e+01 3.52836241e+01
5.05149186e+01 7.23212840e+01 1.03541058e+02 1.48237837e+02
2.12229397e+02 3.03844941e+02 4.35009238e+02 6.22794761e+02
8.91643856e+02 1.27655018e+03 1.82761352e+03 2.61656081e+03
3.74608220e+03 5.36319729e+03 7.67839136e+03 1.09930123e+04]
What am I doing wrong here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|