I am trying to create a bar chart with both positive and negative values using Matplotlib and experiencing difficulty in getting the negative values to show on Y axis. When the code is run, it'll correctly display all positive values (marked in red color) but the negative ones are not showing at all. Instead I'm getting a duplication of the positive values for the string marked "y1". Please see Image 1 attached and my code below.
The code I've used is:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
data = pd.read_csv("C:\samplefile.csv")
fig = plt.figure()
figure(figsize = (22,3))
ax = plt.subplot(111)
x = data['Timing Event']
y = data['Diff Latency'].diff(periods = 1) > 0
y1 = data['Diff Latency'].diff(periods = 1) < 0
y_pos = np.arange(len(x))
plt.bar(y_pos, y, color=(1.0, 0, 0, 0.7))
plt.bar(y_pos, y1, color=(0, 0.6, 0, 0.7))
plt.tight_layout()
plt.show()
The dataset has 2 columns Timing Event in numbers eg.(0,1,2,3....) and used as index and "Diff Latency" which has both negative and positive values. Sample dataset is attached below:
Timing Event Diff Latency
0 -4
1 3
2 1
3 -1
4 2