Skip to content

Instantly share code, notes, and snippets.

@ugo-nama-kun
Created December 23, 2021 15:46
Show Gist options
  • Save ugo-nama-kun/dc6067fc4d371fd52dae796b1e790a8c to your computer and use it in GitHub Desktop.
Save ugo-nama-kun/dc6067fc4d371fd52dae796b1e790a8c to your computer and use it in GitHub Desktop.
Barplot + Angle
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2, 10)
y = np.linspace(2, 0, 10)
err = 0.1 + np.random.rand(len(x)) * 0.3
angle = np.random.rand(len(x)) * np.pi / 3
plt.figure(figsize=(2, 2), dpi=300)
for i in range(len(x)):
dx = err[i] * np.cos(angle[i])
dy = err[i] * np.sin(angle[i])
plt.plot([x[i], x[i] + dx], [y[i], y[i] + dy], "k", linewidth=1)
plt.plot([x[i], x[i] - dx], [y[i], y[i] - dy], "k", linewidth=1)
plt.plot(x, y, "ok", markersize=5)
@ugo-nama-kun
Copy link
Author

Result

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment