Create dotplot.py

This commit is contained in:
Lasse Edfast 2023-01-24 10:55:34 +01:00 committed by GitHub
parent 9080107559
commit a87dd43dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

25
dotplot.py Normal file
View File

@ -0,0 +1,25 @@
from matplotlib import pyplot as plt
import pandas as pd
# Import data and rename relevant column.
file_path = input()
df = pd.read_excel(file_path, header=6, usecols=['Import/export'])
df.rename(columns={'Import/export': 'balance'}, inplace=True)
# Create columns.
df['hour']=df.index
df['y']=df['hour'].apply(lambda x: int(x/120))
df['x']=df['hour'].apply(lambda x: int(x%120))
# Set export to orange and import to grey.
df['color'] = df['balance'].apply(lambda x: 'orange' if x < 0 else 'grey')
# Plot the data.
ax = df.plot(kind='scatter', x='x', y='y', c='color')
# Hide irrelevant names on axes.
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
# Show plot.
plt.show()