この種のヒートマップの図では、matplotlibのimshow
を使用します。
次のようになり、これを使用していくつかのコードの例:ここでは
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig = plt.figure()
ax = plt.add_subplot(111)
heat = ax.imshow(tempmat,
cmap=plt.cm.viridis,
interpolation='none')
# include a colorbar to show the temperature corresponding to each colour
curax = make_axes_locatable(plt..agca())
cbax = curax.append_axes('right', '5%', pad='3%')
fig.colorbar(heat, cax=cbax)
fig.savefig("temperature_heatmap.pdf")
# or instead of saving, just use fig.show()
は、我々は、関数imshowに2次元配列tempmat
に合格しています。あなたのケースでは、指定した.txtファイルのために、これはあなたがこの使用numpyののhistogram2d機能を行うことができRAおよび12月におけるビンの固定セットでの温度値が含まれます:
import numpy as np
# since your example shows semicomma-separated values
dat = np.loadtxt("filename.txt", delimiter=';')
# bin the data in a space of RA and Dec bins, with
# - RAbins = number of bins you want in RA
# - Decbins = number of bins you want in Dec
# (alternatively, supply arrays of bin edges for uneven bin widths)
# - [0, 360] and [-90, 90] or your preferred range
# of RA and Dec to plot temperature bins for
# - weight counts by the temperature of each data point
tsums = np.histogram2d(dat[:, 1], dat[:, 0],
bins=[RAbins, Decbins],
range=[[0, 360], [-90, 90]],
weights=dat[:, 2])
# here we repeat as above without the weighting,
# so that we can find the average temperature in each bin
bincounts = np.histogram2d(dat[:, 1], dat[:, 0],
bins=[RAbins, Decbins],
range=[[0, 360], [-90, 90]],
weights=dat[:, 2])
# divide the resulting 2d arrays to get bin temperatures
tempmat = tsums[0]/bincounts[0]
ここで私がして作られた例です。いくつかのランダムデータ: