Last active
September 29, 2020 20:40
-
-
Save alexandru-dinu/b9aea839a1346593a1ba0ca08fb8a501 to your computer and use it in GitHub Desktop.
Nicer plots
This file contains 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 pylab as pl | |
import seaborn as sns | |
import matplotlib | |
from matplotlib import pyplot as plt | |
from IPython import display | |
%matplotlib inline | |
%config InlineBackend.figure_format = 'retina' | |
sns.set() | |
# or | |
sns.set_style("whitegrid", {'axes.grid' : False}) | |
# auto-update plot | |
if i % REFRESH_INTERVAL == REFRESH_INTERVAL - 1: | |
display.clear_output(wait=True) | |
# histogram with density | |
n, bin_edges = np.histogram(s2, 100) | |
plt.bar((bin_edges[1:]+bin_edges[:-1])/2, n/float(n.sum())) | |
# histogram with centered bars | |
xs = np.arange(n+1) | |
fig, ax = plt.subplots() | |
ys = np.bincount(data) | |
ax.bar(xs, ys/ys.sum(), width=0.5, align='center', alpha=0.5, color='m') | |
plt.scatter(xs, p2(xs), c='r') | |
ax.set(xticks=xs, xlim=[-1, n+1]) | |
# colorbar | |
fig, ax = plt.subplots(figsize=(n, n-2)) | |
im = ax.imshow(mat) | |
fig.colorbar(im) | |
plt.grid(False) | |
ax.text(j, i, text, ha='center', va='center', color='w', fontsize=18) | |
# heatmap | |
data = ... | |
labels = ... | |
fig = plt.figure(figsize=(12, 12)) | |
ax = fig.add_subplot(1, 1, 1) | |
im = ax.imshow(data, cmap='jet', interpolation='nearest') | |
ticks = np.arange(0, len(data), 1) | |
ax.set_xticks(ticks) | |
ax.set_yticks(ticks) | |
ax.set_ylim([-1, len(data)]) | |
ax.set_xlim([-1, len(data)]) | |
ax.set_xticklabels(labels, rotation=0) | |
ax.set_yticklabels(labels, rotation=0) | |
ax.grid(which='major', alpha=0.7) | |
fig.colorbar(im, ax=ax, ticks=np.arange(0, data.max(), data.max() / 20)) | |
plt.tight_layout() | |
plt.savefig('hm.png') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment