X = np.random.normal(0, 1, 100)
Y = np.random.normal(0, 1, 100)
C = np.random.randint(0, 5, 100)
cmap_lst = [plt.cm.rainbow, plt.cm.Blues, plt.cm.autumn, plt.cm.RdYlGn]
f, axes = plt.subplots(1, 4, sharex=True, sharey=True)
f.set_size_inches((16, 4))
for i in range(0, 4):
axes[i].scatter(X, Y, c=C, cmap=cmap_lst[i])
axes[i].set_title("cmap: {}".format(cmap_lst[i].name))
plt.savefig('../../assets/images/markdown_img/180601_plt_cmap_variation.svg')
plt.show()
sample_size = 1000
color_num = 50
X = np.random.normal(0, 1, sample_size)
Y = np.random.normal(0, 1, sample_size)
C = np.random.randint(0, color_num, sample_size)
plt.figure(figsize=(12, 4))
plt.scatter(X, Y, c=C, s=20, cmap=plt.cm.Reds, alpha=0.5)
plt.colorbar(label='color')
plt.savefig('../../assets/images/markdown_img/180601_colorbar_numeric_data.svg')
plt.show()
sample_size = 1000
color_num = 3
X = np.random.normal(0, 1, sample_size)
Y = np.random.normal(0, 1, sample_size)
C = np.random.randint(0, color_num, sample_size)
plt.figure(figsize=(12, 4))
plt.scatter(X, Y, c=C, s=20, cmap=plt.cm.get_cmap('rainbow', color_num), alpha=0.5)
plt.colorbar(ticks=range(color_num), format='color: %d', label='color')
plt.savefig('../../assets/images/markdown_img/180601_colorbar_categorical_data.svg')
plt.show()
(0.5, 0.0, 1.0, 1.0)
(0.0019607843137254832, 0.70928130760585339, 0.92328910610548931, 1.0)
(0.50392156862745097, 0.99998102734872685, 0.70492554690614728, 1.0)
(1.0, 0.70054303759329106, 0.37841105004231035, 1.0)
(1.0, 1.2246467991473532e-16, 6.123233995736766e-17, 1.0)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import itertools
sample_size = 100
x = np.vstack([
np.random.normal(0, 1, sample_size).reshape(sample_size//2, 2),
np.random.normal(2, 1, sample_size).reshape(sample_size//2, 2),
np.random.normal(4, 1, sample_size).reshape(sample_size//2, 2)
])
y = np.array(list(itertools.chain.from_iterable([ [i+1 for j in range(0, sample_size//2)] for i in range(0, 3)])))
y = y.reshape(-1, 1)
df = pd.DataFrame(np.hstack([x, y]), columns=['x1', 'x2', 'y'])
c_lst = [plt.cm.rainbow(a) for a in np.linspace(0.0, 1.0, len(set(df['y'])))]
plt.figure(figsize=(12, 4))
for i, g in enumerate(df.groupby('y')):
plt.scatter(g[1]['x1'], g[1]['x2'], color=c_lst[i], label='group {}'.format(int(g[0])), alpha=0.5)
plt.legend()
plt.savefig('../../assets/images/markdown_img/180601_legend_instead_of_colorbar.svg')
plt.show()
댓글남기기