0

I am producing some plots using Matplotlib (v 3.2.2) and the mplhep tu embed the style used by my collaboration. I noticed that, if I save plots with .png format the output is normal, but if I save them in .pdf I got this message:

'texgyreheros-regular.otf' can not be subsetted into a Type 3 font. The entire font will be embedded in the output.

However it seems that the output plot is always ok. Do you know how to "correct" this or at least hide this sort of warning message? Thanks!

The function I am using to plot is the following:

def PlotVarVsTime( dataframe, title, channel ):
    """
    Function used to plot each row of the dataframe and save it.

    Args:
        dataframe ( dataframe ): the interested dataframe.
        title ( string ): the variable name for plot title.
        channel ( string ): the channel name.
    """   
    
    # Filling a plot, for each dataframe row, with points
    print( "Making plots...", end = "\n" )
    for row_index in dataframe.index:
        
        # Filling single plot for the correspinding row
        columns_container = np.array( [] )
        fig, ax = plt.subplots()
        for column in dataframe.loc[ :, dataframe.columns != "Channel" ]:
            x = Decimal( column )
            y = dataframe[ column ][ row_index ]
            ax.scatter( x, y, c = "blue" )
            columns_container = np.append( columns_container, column )
        
        # Plot settings
        time_start = ft.IntToTime( int( columns_container[ 0 ] ) )
        time_end = ft.IntToTime( int( columns_container[ -1 ] ) )
        ax.set_title( dataframe[ "Channel" ][ row_index ] + "\n" + "(" + time_start + " - " + time_end + ")", fontsize = 15 )
        ax.set_xlabel( "Time (yy/mm/dd/h/m/s)", fontsize = 15 )
        ax.set_ylabel( title, fontsize = 15 )
        ax.set_xlim( columns_container[ 0 ], columns_container[ -1 ] )
        ax.tick_params( axis = 'both', labelsize = 13 )
        ax.xaxis.offsetText.set_fontsize( 15 )

        # Saving plot
        output_name = ft.NameToStr( dataframe[ "Channel" ][ row_index ] )
        print( "Doing " + output_name + " plots..." )
        
        fig.canvas.start_event_loop( sys.float_info.min ) # Workaround for Exception in Tkinter callback
        plt.savefig( "img/" + channel + "/" + title + "/pdf/" + output_name + ".pdf", bbox_inches = "tight", dpi = 100 );
        fig.canvas.start_event_loop( sys.float_info.min ) # Workaround for Exception in Tkinter callback
        plt.savefig( "img/" + channel + "/" + title + "/png/" + output_name + ".png", bbox_inches = "tight", dpi = 100 )
        plt.clf()
        plt.close()
        
        columns_container = np.array( [] )
        
    print()
    print( "Plots have been saved in:", end = "\n" )
    print( "- PDF:", ft.Colored( "img/" + channel + "/" + title + "/pdf/", cl.OutColor.green ), end = "\n" )
    print( "- PNG:", ft.Colored( "img/" + channel + "/" + title + "/png/", cl.OutColor.green ), end = "\n" )

EDIT 1

I am using the option:

plt.style.use( hep.style.ATLAS )

from mplhep library.

3
  • 1
    Hey, do you get the message if you don't save the plot as a pdf but only save it as png? Commented Mar 26, 2022 at 13:00
  • No, I get it only if I save it as pdf. If I save it as png everything is ok. Commented Mar 26, 2022 at 13:02
  • @KJ thanks, however this is not a problem since I have to produce plots on my computer only. Commented Mar 26, 2022 at 13:12

2 Answers 2

1

You probably need to change the type of your font as type 3 seems not be supported for PDFs.

Try changing fonttype to 42.

import matplotlib
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42  

**Source: http://phyletica.org/matplotlib-fonts/

Sign up to request clarification or add additional context in comments.

4 Comments

Unfortunately it doesn't work...
I can't seem to reproduce the message with MPL version '3.4.3'. Can you provide example inputs to test your function?
A thing that can help you is that I am also using the option plt.style.use( hep.style.ATLAS ) from mplhep library: github.com/scikit-hep/mplhep
I have tried the mplhep version '0.3.23' and still can not reproduce the message.
0

I finally solved this issue. The problem was due to the usage of an older version of Matplotlib. Once I've updated the module the problem disappeared.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.