Save multiple plots in a directory using mpld3

36 Views Asked by At

I am using mpld3 to saveplots in html . I am able to save a single plot by giving localpath or a hard coded local file path and file name

But I want to save multiple plots to a specified location . This is what I tried for one plot:

config["output_dir"] is a specified path in the local directory

fake data

new_hpg_groupdf = [
[[0, 1], {'iTOW': [0, 4, 8, 10, 12], 'ionoEst': [20, 25, 19, 17, 21], 'ionoEstAcc': [1, 2, -3, 2, 3]}],
[[0, 2], {'iTOW': [0, 8, 10, 12], 'ionoEst': [60, 65, 59, 61], 'ionoEstAcc': [-2, -1, 2, 0]}],
[[0, 3], {'iTOW': [0, 2, 4, 10, 12], 'ionoEst': [40, 43, 39, 45, 41], 'ionoEstAcc': [3, 2, -3, -2, 3]}]

]

 output_file = config["output_dir"] / "testing.html"
 fig, ax = plt.subplots(2, constrained_layout = True)
 for x in new_hpg_groupdf:
       ax[0].plot(x[1]['iTOW'] , x[1]['ionoEst'] , label=f"{satellite} {x[0][1]}")
       ax[0].set_ylabel("Iono Estimation (TECU)")
       ax[0].set_xlabel("Itows (mSec)")
       ax[0].grid(True)
       ax[0].legend(fontsize=4 , loc='upper left' , bbox_to_anchor=[1.01, 1.02])
       ax[0].set_title('Iono Estimation Output')
       ax[1].plot(x[1]['iTOW'] , x[1]['ionoEstAcc'] , label=f"{satellite} {x[0][1]}")
       ax[1].set_ylabel("Iono Accuracy (TECU)")
       ax[1].set_xlabel("Itows (mSec)")
       ax[1].grid(True)
       ax[1].legend(fontsize=4 , loc='upper left' , bbox_to_anchor=[1.01, 1.02])
       ax[1].set_title('Iono Estimation Accuracy Output')
       mpld3.save_html(fig,output_file)
       plt.close()

But I get an error:

raise ValueError("fileobj should be a filename or a writable file")

ValueError: fileobj should be a filename or a writable file

0

There are 0 best solutions below