Up until recently I have been using Mathematica for my plots. Although it was a real pain and everything had to be done manually, the results where very close to what I wanted. One example is the following:
I really like the grey rounded rectangle in the background of the colorbar. While everything had to be adjusted manually in Mathematica, matplotlib is a lot more automatic and already produced nice results.
But there are still two problems I have:
I am looking forward to any suggestions pointing in the right direction :).
Steps to rotate colorbar ticklabels :Plot a figure. Plot corresponding colorbar. Provide ticks and ticklabels. Set rotation of ticklabels to desired angle.
will map the data in Z linearly from -1 to +1, so Z=0 will give a color at the center of the colormap RdBu_r (white in this case). Matplotlib does this mapping in two steps, with a normalization from the input data to [0, 1] occurring first, and then mapping onto the indices in the colormap.
To plot data and draw a colorbar or legend in one go, pass a location (e.g., colorbar='r' or legend='b' ) to the plotting command (e.g., plot or contour ). To pass keyword arguments to the colorbar and legend commands, use the legend_kw and colorbar_kw arguments (e.g., legend_kw={'ncol': 3} ).
To your second question: you can use a negative labelpad
value to move the label back towards the ticklabels, like this:
import numpy as np
import matplotlib.pyplot as plt
data = np.linspace(0, 10, num=256).reshape(16,16)
cf = plt.contourf(data, levels=(0, 2.5, 5, 7.5, 10))
cb = plt.colorbar(cf)
cb.set_ticklabels([r'$<10^{0}$', 1, 2, r'$10^{14}$', r'$10^{14}+12345678$'])
cb.set_label(r'$n_e$ in $m^{-3}$', labelpad=-40, y=0.45)
plt.show()
Using the parameter y
, you can additionally move the label up or down for better symmetry.
The argument of labelpad
is given in points (1/72 inch). y
accepts values in [0, 1]
, 0.0
is the lower border and 1.0
the upper.
The result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With