This code will create a 3d scatter plot using matplotlib and I am trying to figure out how to save a PNG with the same name as the CSV file I am using to create the pandas dataframe.
I can save the PNG same name as the .py file with this:
output_filename = os.path.splitext(__file__)[0] + '.png'
But how do I modify the code to save the PNG same name as the CSV file?
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import pandas as pd
import os
output_filename = os.path.splitext(__file__)[0] + '.png'
df = pd.read_csv('RTU_101A_Month2dataCSV.csv',index_col='Date', parse_dates=True)
OAT = pd.Series(df['OAT'])
RAT = pd.Series(df['RAT'])
MAT = pd.Series(df['MAT'])
df['hour'] = df.index.hour
df_OATrat = (OAT - RAT)
df_MATrat = (MAT - RAT)
df_Hour = df['hour']
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = df_MATrat
y = df_Hour
z = df_OATrat
ax.scatter(x, y, z, c='g', marker='x')
ax.set_xlabel('MAT-RAT')
ax.set_ylabel('Hours in Day')
ax.set_zlabel('OAT-RAT')
plt.show()
plt.savefig(output_filename)