I have the following lines of code to generate a heatmap (pcolormesh
).
import matplotlib.pyplot as plt
import numpy as np
vals = np.linspace(-np.pi/2, np.pi/2, 101)
x, y = np.meshgrid(vals, vals)
z = np.abs(np.sinc(x) * np.sinc(y))
xDeg = np.rad2deg(x)
yDeg = np.rad2deg(y)
plt.pcolormesh(xDeg, yDeg, z, cmap = 'jet', vmin = 0, vmax = 1)
plt.colorbar()
plt.axis([-90, 90, -90, 90])
ticks = np.linspace(-90, 90, 13)
plt.xticks(ticks)
plt.yticks(ticks)
print np.mean(z) # 0.186225110029
print np.sqrt(np.mean(z**2)) # 0.295710882276
plt.show()
It produces this image:
I'd like to place:
Any input?
The axhline() function in pyplot module of matplotlib library is used to add a horizontal line across the axis. Parameters: y: Position on Y axis to plot the line, It accepts integers. xmin and xmax: scalar, optional, default: 0/1.
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} ).
That was easier than expected. I didn't realize colorbar has a plottable axis in plt.colorbar().ax
cb = plt.colorbar()
cb.ax.plot(0.5, mean, 'w.') # my data is between 0 and 1
cb.ax.plot([0, 1], [rms]*2, 'w') # my data is between 0 and 1
# Note: would need to scale mean/rms to be between 0 and 1
Looks like the x-axis is (0, 1) and y-axis (dataMin, dataMax) (0, 1).
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