I have a a snippet of Python code to plot a very basic bar graph which represents a list containing pre-calculated percentages:
def plot_errors_percent_bar_graph(list):
fig, ax = plt.subplots()
x_labels = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
ax.bar(x_labels, list, color='green')
ax.set_ylabel('Percentage of Number of Errors')
ax.set_xlabel('Labels')
ax.set_title('Total Percentage Number of Errors')
plt.show(block=False)
plt.pause(0.001)
The graph only shows the highest percentage from the list on the y-axis (e.g. 80% on the plot shown below):
How can I always make the graph show from 0% to 100% even if the list doesn’t contain a value near that?
>Solution :
With matplotlib you can define the limits of values on each axis. To solve your problem, just add the line ax.set_ylim(ymin=0, ymax=100) in your fonction.
