Create dotplot.py
This commit is contained in:
parent
9080107559
commit
a87dd43dca
25
dotplot.py
Normal file
25
dotplot.py
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user