Created
August 1, 2013 01:46
-
-
Save joferkington/6127799 to your computer and use it in GitHub Desktop.
Suggestion on: http://stackoverflow.com/questions/17949475/intelligibly-displaying-multiple-dense-scatter-plots-on-one-axis-in-python-mat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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