Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to save plot to new Folder

I would like to save my matplotlib plot to the new generated Folder.
I just dont get it to save my plot to this path…

This is my Code so far:

now = datetime.now()
current_time = now.strftime("%m_%d_%Y, %H_%M_%S")
dir_name = "Messdaten " + current_time

os.mkdir(dir_name)

my_path = os.path.abspath(os.getcwd())
    
save_path = my_path + "\\" + dir_name

path = Path(save_path)

plt.savefig(path)

I would be grateful for any help!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try use os module:

import os
my_path = os.path.abspath(__file__) # Figures out the absolute path 
fig.savefig(my_path + '/Sub Directory/graph.png')

or:

script_dir = os.path.dirname(__file__)
results_dir = os.path.join(script_dir, 'Results/')
sample_file_name = "sample"

os.makedirs(results_dir, exist_ok=True)
plt.savefig(os.path.join(results_dir, sample_file_name))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading