I need to produce an image like below with my own x(phase),y(energy) and c (chi) values.
My x(phase bins) have 10 equal binsize from 0 to 2.0 whereas the y value is a bit more complicated with 50 binsize
x = np.arange(0, 2.2, 0.2)
ymin = np.array([300,305,310,..400,410,420,..,500,520,..,600,630,..700,750,..3000])
ymax = np.array([305,310,315,..410,420,430,..,520,540,..,630,660,..750,800,..3500])
There is also my colormap array (chi) with the same binsize as my y values
c = np.random.uniform(low=-10, high=10, size=50)
So for each x value, there exist a colormap value, that should be "colored" between ymin and ymax (like the image above). For instance for first x bin (0.0-0.2) and first y bin (300-500), the colormap is 8, so I want a pixel to be filled between these x and y values with an appropriate color map (red in this case).
Based on what I read on the web, there is more or less two approach to produce such a plot.
First one is based on the python scatter function. My code and produced image is below
import matplotlib
sns.set_style("ticks")
sns.set_context("talk")
cmap = "seismic"
norm = matplotlib.colors.Normalize(vmin=-11,vmax=11)
def rep(phase1,phase2):
ff = np.full(shape=len(emax),fill_value=((phase1+phase2)/2.),dtype=float)
return ff
plt.figure(figsize=(16,9))
plt.rcParams["font.family"] = "Times New Roman"
ax = plt.subplot()
y = ((emin+emax)/2)/1000
x1,c1 = rep(0,0.2),chi1
x2,c2 = rep(0.2,0.4),chi2
x3,c3 = rep(0.4,0.6),chi3
x4,c4 = rep(0.6,0.8),chi4
x5,c5 = rep(0.8,1.0),chi5
x6,c6 = rep(1.0,1.2),chi1
x7,c7 = rep(1.2,1.4),chi2
x8,c8 = rep(1.4,1.6),chi3
x9,c9 = rep(1.6,1.8),chi4
x10,c10 = rep(1.8,2.0),chi5
xval = np.array([x1,x2,x3,x4,x5,x6,x7,x8,x9,x10])
cval = np.array([c1,c2,c3,c4,c5,c6,c7,c8,c9,c10])
for x, c in zip(xval, cval):
ax.scatter(x,y, s=(x*y)*fig.dpi,c=c,cmap=cmap,norm=norm)
PCM = ax.get_children()[2]
cbar = plt.colorbar(PCM, ax=ax)
cbar.set_label(r'$\Delta \chi$', rotation=90, fontsize=25)
cbar.ax.tick_params(labelsize=22)
cbar.set_ticks(np.arange(-10, 11, 1))
ax.set_xlabel(r'Phase $\phi$', fontsize=28)
ax.set_ylabel(r'Energy (keV)', fontsize=28)
ax.set_xticks(np.arange(0, 2.2, 0.2))
ax.set_yticks([0.2,0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5])
ax.tick_params(axis='both', which='major', labelsize=28)
plt.tight_layout()
However, it does not produce what I expected and creates circles at specific points instead of rectangular (filled values between x and y bins). I played with the "s" but didnt change the results. In Here, it shows how to produce a pixel (rather than circle) but it did not work for me and still produces circle.
There is also approach based on pyplot.imshow like here and here but in there, they use a 2D (Z values) and I quite didn't understand how to integrate different colormaps in there.
What is the best approach to plot such image.