I am trying to create a plot with mpld3 and save it to an html. When i run my code I get a warning resulting in an empty plot:

UserWarning: Blended transforms not yet supported. Zoom behavior may not work as expected. warnings.warn("Blended transforms not yet supported.

I am seeing this only problem when I try to save it in an html. Things work when i save it to pdf

Below is my code:

    with open(output_file1, 'w') as file:
    #with PdfPages(output_file) as pdf:
        firstPage = plt.figure(figsize=(8.27, 11.69))
        firstPage.clf()
        txt = "This is the title page"
        firstPage.text(
            0.05,
            0.95,
            txt,
            transform=firstPage.transFigure,
            size=24,
            va="top",
            ha="left",
        )
        #pdf.savefig()
        plt.close()

        hours_locator = mdates.HourLocator(interval=1)
        h_fmt = mdates.DateFormatter("%H:%M:%S")

        for data in results:
            fig, (ax0, ax1) = plt.subplots(nrows=2, ncols=1, figsize=(8.27, 11.69))
            # df["iqi"].plot(ax=ax0, color="steelblue")
            ax2 = ax0.twinx()
            ax0.axhline(y=config["iqi_threshold"], color="salmon" , label='Iono Quality Threshold')
            ax0.plot(results['df']['iTOW'], results['df']['iqi'], color="steelblue", label='Iono Quality Behaviour')
            ax0.plot(results['df']['iTOW'], results['df']['numSv'], color="green", label='No of SVs')
            ax0.set_ylabel("SPARTN IQI")
            ax0.set_xlabel("iTOW [s]")
            ax0.grid(True)
            ax0.set_title(input_file_path, wrap=True)
            ax2.set_ylabel('No of SVs', color = 'g')
            ax2.set_ylim(0, 45)
            fig.legend(loc = 'upper right',bbox_to_anchor=(1, 1),borderaxespad=0.)
            txt = "+" * 20

            for iqi_event in results["iqi_alerts"]:
                txt += "\n|{:^10.0f}|{:^10.0f}|{:^10.0f}|{:^10.0f}|{:^10}|".format(
                    iqi_event["start_itow"],
                    iqi_event["end_itow"],
                    iqi_event["cut_start_itow"],
                    iqi_event["cut_end_itow"],
                    iqi_event["long"],
                )
                ax0.axvspan(
                    iqi_event["start_itow"],
                    iqi_event["end_itow"],
                    color="lightblue",
                )
                
                table={'Log File' : [input_file_path],'Start Itow' : iqi_event["start_itow"],'End Itow': iqi_event["end_itow"],'Unique SV count' : unique_sv_count }
                df_table=pd.DataFrame(table)
                fig1 = plt.figure(figsize=(9,2))
                ax0.table(cellText=df_table.values, colLabels=df_table.columns,cellLoc='center', loc='bottom', bbox=[0.01,-0.7,0.85,0.2] )

                mpld3.save_html(fig,file)    
                #pdf.savefig()
                plt.close()     
            
            txt += "\n" + "+" * 20
            ax1.text(0, 1, txt, size=12, va="top", ha="left")
            ax1.axis("off")
            mpld3.save_html(fig1,file)
            #pdf.savefig()
            plt.close()

Below is the correct output I get when I save it in a pdf:

enter image description here enter image description here

Output in an html page (Empty plot with table missing):

enter image description here

0

There are 0 best solutions below