0
    raise RuntimeError('No mappable was found to use for colorbar '

some scatter plots in loop are empty and having None values (correctly). as i'm plotting around 100 scatter in loop, i have colorbar error when scatter is empty. the only way is elimination : plt.colorbar() from my code.which is not a solution.


T1 = []
T2 = []
T3 = []
for ii, (xe,ye) in enumerate(zip(T1,T2)):
            plt.scatter([xe]*len(ye),ye, c=T3[ii],cmap='Paired',s=100,vmin=0,vmax=1,marker="x")
        plt.colorbar()
        plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))
        plt.savefig(f"plot/{mac}- Test{a1}-delta{b1}.svg",format='svg', bbox_inches='tight')
        plt.clf()

I want my scatter keeps plotting and ignore the Runtime error. or keeps ploting the colorbar regardless of value None.

  • You could always generate the colorbar from a dummy `ScalarMappable`, e.g. `plt.colorbar(matplotlib.cm.ScalarMappable(cmap='Paired', norm=plt.Normalize(vmin=0,vmax=1)))` – JohanC Dec 13 '22 at 18:01

0 Answers0