Currently I have the problem that I do not get the steps on the y-axis (score) changed. My representation currently looks like this:
However, since only whole numbers are possible in my evaluation, these 0.5 steps are rather meaningless in my representation. I would like to change these steps from 0.5 to 1.0. So that I get the steps [0, 1, 2, 3, ...]
instead of [0.0, 0.5, 1.0, 1.5, 2.0, ...]
.
My code broken down to the most necessary and simplified looks like this:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# some calculations
x = np.arange(len(something)) # the label locations
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, test1_means, width, label='Test 1')
rects2 = ax.bar(x + width/2, test2_means, width, label='Test 2')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Something to check')
ax.set_xticks(x, something)
ax.legend()
ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)
fig.tight_layout()
plt.show()
In addition, after research, I tried setting the variable ax.set_yticks
or adjusting the fig
. Unfortunately, these attempts did not work.
What am I doing wrong or is this a default setting of matplotlib at this point?
Edit after comment:
My calculations are prepared on the basis of Excel data. Here is a reproducible code snippet with the current values how the code might look like in the final effect:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
stories = ["A", "B", "C", "D", "E"]
test1_means = [2, 3, 2, 3, 1]
test2_means = [0, 1, 0, 0, 0]
x = np.arange(len(stories)) # the label locations
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, test1_means, width, label='Test 1')
rects2 = ax.bar(x + width/2, test2_means, width, label='Test 2')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Something')
ax.set_xticks(x, stories)
ax.legend()
ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)
fig.tight_layout()
plt.show()