Skip to content

Instantly share code, notes, and snippets.

@Kensuke-Mitsuzawa
Created February 9, 2021 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kensuke-Mitsuzawa/c07a7cda5c23ff8086d257ca6d9c7d83 to your computer and use it in GitHub Desktop.
Save Kensuke-Mitsuzawa/c07a7cda5c23ff8086d257ca6d9c7d83 to your computer and use it in GitHub Desktop.
render multi-row scatter graph
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas
# 多次元配列をつくる
x_tensor = np.random.uniform(size=(3, 10, 2), low=1.0, high=20)
#
mark_value = [2.5, 5.5]
# 散布図の最大値、最小値を決定
history_x_lim = [np.min(x_tensor[:, :, 0].flatten()),
np.max(x_tensor[:, :, 0].flatten())]
history_y_lim = [np.min(x_tensor[:, :, 1].flatten()),
np.max(x_tensor[:, :, 1].flatten())]
if mark_value[0] < history_x_lim[0]:
history_x_lim[0] = mark_value[0]
elif history_x_lim[1] < mark_value[1]:
history_x_lim[1] = mark_value[1]
if mark_value[1] < history_y_lim[0]:
history_y_lim[0] = mark_value[1]
elif history_y_lim[1] < mark_value[1]:
history_y_lim[1] = mark_value[1]
fig, axes = plt.subplots(nrows=len(x_tensor), ncols=1)
for n_iter, matrix_at_n in enumerate(x_tensor):
df_theta_history = pandas.DataFrame(matrix_at_n, columns=['x', 'y'])
df_theta_history['label'] = 'points'
df_theta_history = df_theta_history.append(pandas.Series(mark_value + ['*'],
index=['x', 'y', 'label'],
name='mark'))
axes[n_iter].set(xlim=history_x_lim, ylim=history_y_lim)
sns.scatterplot(x='x', y='y', data=df_theta_history, hue='label', ax=axes[n_iter])
axes[n_iter].set_title(f'Theta distribution at N = {n_iter}')
fig.savefig('plot_practice.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment