I have a script that plots out a heat map using matplotlib. Range of X-axis value = (-180 to +180) and Y-axis value =(0 to 180). The 2D heatmap colours areas in Rainbow according to the number of points occurring in a specified area in the x-y graph (defined by the 'bins' - see code below). In this case, x = values_Rot and y = values_Tilt (see below for code).
As of now, this script colours the 2D-heatmap on a log_base10 scale. However, the range of my data is small and I am thinking of changing the base from 10 to base 2.
Is there a way to colour the heatmap by changing the base from 10 to 2 in this code?
Also, I find that the image which has popped up after running this script clearly shows the heatmap. However, when I see the PNG image that has been saved, I see it is a blank image (pure white image) with nothing on it. Is there a way to save the figure - am I missing something while importing?
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
values_Rot = []
values_Tilt = []
values_Psi = []
for line in data:
try:
values_Rot.append(float(line.split()[rot_number]))
values_Tilt.append(float(line.split()[tilt_number]))
values_Psi.append(float(line.split()[psi_number]))
except:
print ('This line didnt work, it may just be a blank space. The line is:' + line)
# Change the values here if you want to plot something else, such as psi.
# You can also change how the data is binned here.
plt.hist2d(values_Rot, values_Tilt, norm=mpl.colors.LogNorm(), bins=100,)
plt.set_cmap('jet')
plt.colorbar()
plt.show()
plt.savefig('name_of_output.png')