Skip to content

Instantly share code, notes, and snippets.

@YimianDai
Created August 3, 2019 18:19
Show Gist options
  • Save YimianDai/489a83612a26c5ae0e71ffb64c68f777 to your computer and use it in GitHub Desktop.
Save YimianDai/489a83612a26c5ae0e71ffb64c68f777 to your computer and use it in GitHub Desktop.
Plot Dataset Relative Scale
from matplotlib import pyplot as plt
import numpy as np

hist_arr = np.load("hist_arr.npy")
hist_sum = np.sum(hist_arr)

hist_cum = np.cumsum(hist_arr) / hist_sum
x_axis = np.linspace(0, 1, 512)


print("hist_cum: ", hist_cum)


coco_x = [0.00618, 0.01081, 0.01545, 0.01932, 0.02086, 0.02936, 0.03091, 0.03477,
              0.03941, 0.04250, 0.04945, 0.05641, 0.06336, 0.07032, 0.07805, 0.08887,
              0.09737, 0.11515, 0.13447, 0.14838, 0.16074, 0.17774, 0.1932, 0.20866,
              0.22179, 0.23725, 0.26275, 0.28825, 0.30989, 0.33153, 0.36321, 0.38872,
              0.41422, 0.44359, 0.46291, 0.49691, 0.52396, 0.55023, 0.57342, 0.59583,
              0.61592, 0.63833, 0.6677, 0.69784, 0.71329, 0.74343, 0.77125, 0.79598,
              0.82303, 0.85317, 0.89026, 0.9204, 0.95286, 0.97372, 0.99536]
coco_x = np.array(coco_x)
coco_y = [0, 0.017391, 0.04, 0.066087, 0.073043, 0.13391, 0.14435, 0.16522, 0.19304,
              0.21913, 0.25391, 0.29565, 0.3287, 0.36696, 0.39826, 0.44, 0.46957, 0.52348,
              0.57217, 0.60174, 0.62783, 0.65739, 0.68174, 0.70435, 0.72174, 0.74087, 0.7687,
              0.79304, 0.81043, 0.82609, 0.84696, 0.86087, 0.87304, 0.88696, 0.89739, 0.90957,
              0.91826, 0.92696, 0.93391, 0.94087, 0.94609, 0.94957, 0.95826, 0.96174, 0.96522,
              0.97217, 0.97565, 0.97913, 0.98261, 0.98435, 0.98783, 0.98957, 0.99304, 0.99478, 1]
coco_y = np.array(coco_y)

imagenet_x = [0.00463, 0.02782, 0.04482, 0.06336, 0.09891, 0.12287, 0.14451, 0.16074, 0.21561,
         0.30912, 0.41577, 0.53168, 0.66074, 0.77202, 0.86476, 0.93277, 0.97836, 0.99382]
imagenet_y = [0, 0, 0.0052083, 0.015625, 0.038194, 0.059028, 0.076389, 0.092014, 0.1441, 0.23611,
         0.34375, 0.46875, 0.61632, 0.73958, 0.84375, 0.91146, 0.95312, 0.9809]
imagenet_x = np.array(imagenet_x)
imagenet_y = np.array(imagenet_y)

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)

# Major ticks every 20, minor ticks every 5
major_ticks = np.linspace(0, 1, 11)
minor_ticks = np.linspace(0, 1, 51)
ax.set_xticks(major_ticks)
ax.set_xticks(minor_ticks, minor=True)
ax.set_yticks(major_ticks)
ax.set_yticks(minor_ticks, minor=True)

# And a corresponding grid
ax.grid(which='both')
# ax.grid(True)

# Or if you want different settings for the grids:
ax.grid(which='minor', alpha=0.2)
ax.grid(which='major', alpha=0.5)

plt.plot(imagenet_x, imagenet_y, coco_x, coco_y, x_axis, hist_cum)
plt.legend(('ImageNet', 'COCO', 'Dice'))
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('Relative scale')
plt.ylabel('CDF (Scale)')
plt.tick_params( labelsize='small')

# plt.grid(True)
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment