Skip to content

Instantly share code, notes, and snippets.

@joferkington
Created August 1, 2013 01:46
Show Gist options
  • Save joferkington/6127799 to your computer and use it in GitHub Desktop.
Save joferkington/6127799 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
num = 100000
x, y = np.random.random((2, num))
category = np.random.randint(1, 5, num)
# Using multiple "plot" calls
fig, ax = plt.subplots()
ax.set_color_cycle(['black', 'red', 'orange', 'yellow'])
for i in range(1, 5):
mask = category == i
ax.plot(x[mask], y[mask], marker='+', linestyle='none')
ax.set(title="The way you're probably plotting things now")
# Using a single "scatter" call
fig, ax = plt.subplots()
cmap = ListedColormap(['black', 'red', 'orange', 'yellow'])
ax.scatter(x, y, c=category, cmap=cmap, marker='+')
ax.set(title="Using scatter to plot instead")
ax.axis([0, 1, 0, 1])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment