Pyplot doesn't show first bar in a grouped bar chart

Viewed 24

somehow is pyplot not showing the first bar in bar plot i generated. I assume that the y scale is not set up correctly but nothing i tried solved the problem. The y-axis start with the first(and lowest) value. How do i change it without completely destroying the scale?

CODE:

from matplotlib import pyplot as plt
import numpy as np


x = np.arange(4)  # the label locations
width = 0.2  # the width of the bars

plt.bar(x-0.2, one_digit_10_pre_run, width, color='cyan')
plt.bar(x, two_digit_10_pre_run, width, color='orange')
plt.bar(x+0.2, three_digit_10_pre_run,width,color='green')

plt.xticks(x, ['10', '20', '30', "100"])
plt.xlabel("Amount of Input Values")
plt.ylabel("Execution Times [Seconds]")
plt.legend(["0 Digits extra", "1 Digit Extra", "2 Digit Extra"])
plt.show()

the data looks as follows:

['0.021636664867401074', '0.023439047336578315', '0.023759815692901566', 027013454437255814']
['  0.021725461034491467', '  0.020219009701568258', '  0.021416027545928907', '  0.024219112396240184']
['  0.02276699304580684', '  0.021797661781310988', '  0.025862150192260697', '  0.026579418182373003']

Plot looks like this:

link to plot

1 Answers

it looks like the arrays are lists of strings, but should be numbers.

with numbers the code looks like this:

from matplotlib import pyplot as plt
import numpy as np

x = np.arange(4)  # the label locations
width = 0.2  # the width of the bars

one_digit_10_pre_run = [0.021636664867401074, 0.023439047336578315, 0.023759815692901566, 0.27013454437255814]
two_digit_10_pre_run = [0.021725461034491467, 0.020219009701568258, 0.02141602754592890, 0.024219112396240184]
three_digit_10_pre_run = [0.02276699304580684, 0.021797661781310988, 0.025862150192260697, 0.026579418182373003]


plt.bar(x-0.2, one_digit_10_pre_run, width, color='cyan')
plt.bar(x, two_digit_10_pre_run, width, color='orange')
plt.bar(x+0.2, three_digit_10_pre_run,width,color='green')

plt.xticks(x, ['10', '20', '30', "100"])
plt.xlabel("Amount of Input Values")
plt.ylabel("Execution Times [Seconds]")
plt.legend(["0 Digits extra", "1 Digit Extra", "2 Digit Extra"])
plt.show()

and the chart looks like this:

enter image description here

Related