2

I am utilizing an Azure Synapse Analytics Workspace where I am running a PYSpark notebook from the Notebook tab of the workspace.

The workspace is also connected to an Azure Data Lake Storage Gen 2, which has a container called filesystem.

Usually to save files I write them in Spark using the ABFSS path after exporting my DataFrame.

UC_export=spark.createDataFrame(Error_Report.astype(str), verifySchema=False)
UC_export.coalesce(1).write.format('csv').mode('overwrite').save('abfss://[Container Name].dfs.core.windows.net/Assets_DQ/Error_Report.csv', header=True)

However for the following code, I have no idea how to save figures. How do I run a loop which can export the *.png files to the ABFSS container?

for error in Unique_Conso_df_check['Rule Broken'].unique():
    for column in suitable_columns:
        fig = plt.figure()
        ax = plt.subplot(111)
        pd.crosstab(Unique_Conso_df_Error[column],Unique_Conso_df_Error[error]).plot(kind='bar', rot = 90, ax=ax, figsize=[20,10])
        ax.get_figure().savefig(savedirectory+'/densityplot_'+str(column)+'.png')
        plt.show()
Darren Teo
  • 21
  • 1

1 Answers1

-1

As suggested by User CHEEKATLAPRADEEP-MSFT - Stack Overflow, try following code to save png file for ABFSS container:

plt.savefig(' [abfss://<FileSystemName>@<StorageName>.dfs.core.windows.net/FilePath/test.png](mailto:abfss://%3cFileSystemName%3e@%3cStorageName%3e.dfs.core.windows.net/FilePath/test.png)')  

Alternatively, you can also try as suggested by User imLightSpeed - Stack Overflow:

plt.savefig("image{:04}.jpeg".format(n))  

References: Saving Matplotlib Output to Blob Storage on Databricks - Stack Overflow, python - How can I use the function plt.savefig() to save many graphics inside a loop for or while? - Stack Overflow , python - How do I save a new graph as png with every iteration of a loop - Stack Overflow and python - matplotlib savefig performance, saving multiple pngs within loop - Stack Overflow

MadhurajVadde-MT
  • 889
  • 1
  • 2
  • 10