使用 Matplotlib 以 pdf 格式保存绘图时出现奇怪的消息,为什么?

Strange message when saving a plot in pdf format with Matplotlib, why?

我正在使用 Matplotlib (v 3.2.2) 制作一些图,并且 mplhep 嵌入了我合作使用的样式。我注意到,如果我用 .png 格式保存图,输出是正常的,但如果我将它们保存为 .pdf 格式,我收到此消息:

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

不过输出图好像一直没问题。你知道如何“纠正”这个或至少隐藏这种警告信息吗?谢谢!

我用来绘图的函数如下:

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" )

编辑 1

我正在使用选项:

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

来自 mplhep 图书馆。

您可能需要更改字体类型,因为 PDF 似乎不支持类型 3。

尝试将 fonttype 更改为 42。

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

**来源:http://phyletica.org/matplotlib-fonts/