Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Created September 1, 2019 06:01
Show Gist options
  • Save DataSolveProblems/fa2032d81edfc353947fd9bdc742aed8 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/fa2032d81edfc353947fd9bdc742aed8 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_title('Horizontal Bar graph with error mark demo')
ax.set_xlabel('x label title')
ax.set_ylabel('y label title')
y_vals = [10, 14, 12, 11, 13]
y_labels = ['y' + str(i) for i in range(5)]
y_position = [0, 1, 2, 3, 4]
x_vals = 10 * np.random.rand(len(y_vals)) + 3
error_mark = np.random.rand(len(y_vals))
ax.barh(y_position, y_vals, xerr=error_mark, capsize=5, align='center', color='blue', alpha=0.6, ecolor='red')
ax.set_yticks(y_position)
ax.set_yticklabels(y_labels)
ax.invert_yaxis()
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment