Skip to content

Instantly share code, notes, and snippets.

@yoki
Last active October 22, 2020 17:03
Show Gist options
  • Save yoki/2e22c780c24f75df47a0b0b0cb23762c to your computer and use it in GitHub Desktop.
Save yoki/2e22c780c24f75df47a0b0b0cb23762c to your computer and use it in GitHub Desktop.
# 1_matplotlib
# 2_seaborn
import matplotlib.pyplot as plt
# https://matplotlib.org/tutorials/introductory/pyplot.html
# simple line plot
plt.plot([1, 2, 3, 4])
plt.show()
# scatter plot:plot(<x>, <y>,<format string from matlab>)
plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'ro')
plt.axis([0, 6, 0, 20]) # set axix range: [xmin, xmax, ymin, ymax]
plt.show()
# mutlile scatter plots
# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()
# multiple charts by categories
names = ['group_a', 'group_b', 'group_c']
values = [1, 10, 100]
plt.figure(1, figsize=(9, 3))
plt.subplot(131)
plt.bar(names, values)
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values)
plt.suptitle('Categorical Plotting')
plt.show()
# histgram
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)
n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
plt.axis([40, 160, 0, 0.03])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment