import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import MaxNLocator

import colormaps as cmaps
plt.register_cmap(name='viridis', cmap=cmaps.viridis)
plt.set_cmap(cmaps.viridis)


x=np.linspace(0,10,11)
y=np.linspace(100,110,11)
z=np.random.rand(len(x),len(y))


#min,max=z.min(), z.max()
min,max=0,1

# mask all quantities you do not want to be shown (e.g. negative values, zeros...)
z=np.ma.masked_less_equal(z,0.1)

p=plt.pcolormesh(x,y,z,edgecolors="w",lw=1,vmin=min,vmax=max) 
plt.colorbar()
plt.show()
"""
#mask all values < 0.2:
z1=np.ma.masked_where(z<0.1,z)
#levels = MaxNLocator(nbins=15).tick_values(min,max)
p=plt.pcolormesh(x,y,z1,edgecolors="w",lw=1,vmin=min,vmax=max) 
plt.colorbar()

# plot masked values in red:
z2=np.ma.masked_where(z>=0.1,z)
from matplotlib import colors as c
conlyred=c.ListedColormap(["r"])
p=plt.pcolormesh(x,y,z2,cmap=conlyred,edgecolors="w",lw=1,alpha=0.4) 
"""


#### or with real data:
"""
rdata=...
tdata=...

if True:
  fig=plt.figure()
  ax1=plt.gca()
  binx=np.linspace(0,2,100)
  biny=np.linspace(0,2.5*median(tdata),100)
  h,xedges,yedges=np.histogram2d(rdata,tdata,bins=[binx,biny])

  xpos=(xedges[:-1]+xedges[1:])/2.
  ypos=(yedges[:-1]+yedges[1:])/2.
  h=np.ma.masked_less_equal(h,0.1)
  p=plt.pcolormesh(xpos,ypos,h.T) #,edgecolors="w",lw=1,vmin=np.min(h),vmax=np.max(max)) 
  cbar=plt.colorbar()
  cbar.set_label('Counts per cell')
"""

# with lognorm

"""

from matplotlib.colors import LogNorm
p=plt.pcolormesh(xpos,ypos,h.T,edgecolors="w",lw=0.1,norm=LogNorm())

"""

# real data including added 1d histos as twinx/twiny
"""
rdata=...
tdata=...

if True:
  fig=plt.figure()
  ax1=plt.gca()
  binx=np.linspace(0,2,100)
  biny=np.linspace(0,2.5*median(tdata),100)
  h,xedges,yedges=np.histogram2d(rdata,tdata,bins=[binx,biny])

  xpos=(xedges[:-1]+xedges[1:])/2.
  ypos=(yedges[:-1]+yedges[1:])/2.
  h=np.ma.masked_less_equal(h,0.1)
  p=plt.pcolormesh(xpos,ypos,h.T) #,edgecolors="w",lw=1,vmin=np.min(h),vmax=np.max(max)) 
  cbar=plt.colorbar()
  cbar.set_label('Counts per cell')

  histlw=2
  ax2=ax1.twiny()
  hist,binedges=np.histogram(tdata,biny)
  bincenter=(binedges[:-1]+binedges[1:])/2.
  plt.step(hist,bincenter,where='pre',color="r",lw=histlw)
  plt.xlabel("y hist (red)")

  ax3=ax1.twinx()
  hist,binedges=np.histogram(ssr,binx)
  bincenter=(binedges[:-1]+binedges[1:])/2.
  plt.step(bincenter,hist,where='post',color="orange",lw=histlw)
  plt.ylabel("x hist (orange)")
"""
