scikit-hep / mplhep

Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling
https://mplhep.readthedocs.io
MIT License
182 stars 63 forks source link

Label formatting issue #491

Open schaefes opened 2 months ago

schaefes commented 2 months ago

Hello, I experienced a weird formatting of the llable next to the CMS logo. It creates a vertical offset of the llabel relative to the CMS logo. I have played around with different parameters like loc, fontsize, pad, but none fixed the issue. In fact the addition of a fondsize=18 argument increased the vertical offset. This is a snipped of the code:

        figsize = (len(features) * 1.6, len(ds) * 1.1)
        fig2 = plt.figure(figsize=figsize)
        plt.style.use(mplhep.style.CMS)
        mplhep.cms.label(llabel='Private Work', data=False, fontsize=18)
        corrcoef_str = np.round(corrcoef, decimals=2).astype(str)
        for i, _ in enumerate(corrcoef.tolist()):
            for j, _ in enumerate(corrcoef.tolist()[i]):
                corrcoef_str[i][j] = "{:.2f}".format(corrcoef[i][j])
        # plot the coefficients in a heatmap
        im = plt.imshow(corrcoef, vmin=-1, vmax=1)
        im_ratio = corrcoef.shape[0] / corrcoef.shape[1]
        plt.colorbar(im, aspect=im_ratio * 20)
        plt.xticks(np.arange(len(features)), labels=features, rotation=90)
        plt.yticks(np.arange(len(ds)), labels=ds)

        # set the grid
        plt.xticks(np.arange(corrcoef.shape[1] + 1) - .5, minor=True)
        plt.yticks(np.arange(corrcoef.shape[0] + 1) - .5, minor=True)
        plt.grid(which="minor", color="black", linestyle='-', linewidth=.25)

        # annotate the the heatmap with the values in each cell
        for i in range(corrcoef.shape[0]):
            for j in range(corrcoef.shape[1]):
                plt.annotate(str(corrcoef_str[i][j]), xy=(j, i), ha='center', va='center', color='black',
                            fontsize=21)
        plt.savefig(os.path.join(save_path, f'corrcoef_fold{f}_ensemble{e}.pdf'))

I will append screenshots of the labels with and without the fontsize argument as well as files specifying my technical setup. My setup is embedded in an analysis framework called coulmnflow. mplhep_screenshot_fontsize18 label_offset venv_requirements.txt model_specifications.txt venv_requirements.txt model_specifications.txt mplhep_screenshot_fontsize18 label_offset