Skip to content

Commit de623a1

Browse files
committed
Add Example: Repository Distribution Histogram
1 parent c439162 commit de623a1

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

examples/data_distribution/histogram/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ target_link_libraries(example_histogram_13 PUBLIC matplot)
3939

4040
add_executable(example_histogram_14 histogram_14.cpp)
4141
target_link_libraries(example_histogram_14 PUBLIC matplot)
42+
43+
add_executable(example_histogram_15 histogram_15.cpp)
44+
target_link_libraries(example_histogram_15 PUBLIC matplot)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#include <cmath>
2+
#include <matplot/matplot.h>
3+
#include <vector>
4+
5+
std::vector<int> n_stars();
6+
7+
int main() {
8+
using namespace matplot;
9+
10+
auto ax_1 = axes();
11+
auto ax_2 = axes({0.4, 0.4, 0.45, 0.45});
12+
13+
std::vector<int> stars = n_stars();
14+
15+
axes(ax_1);
16+
hist(stars);
17+
xlabel("Stars");
18+
ylabel("Repositories");
19+
title(num2str(stars.size()) + " Most Popular C++ Repositories");
20+
21+
axes(ax_2);
22+
title(num2str(size_t(stars.size() * 0.1)) + " to " + num2str(stars.size()) +
23+
" Most Popular C++ Repositories");
24+
stars.erase(stars.begin(), stars.begin() + stars.size() * 0.1);
25+
hist(stars);
26+
27+
show();
28+
return 0;
29+
}
30+
31+
std::vector<int> n_stars() {
32+
return std::vector<int>{
33+
148679, 85962, 68056, 53565, 48484, 45219, 43848, 42440, 37433, 35587,
34+
33400, 30872, 27882, 27641, 24055, 21753, 21510, 20971, 20384, 20216,
35+
19824, 19637, 18628, 17791, 17724, 17202, 17182, 17058, 16665, 16660,
36+
16067, 16032, 15632, 15211, 15088, 14824, 14822, 14728, 14674, 14620,
37+
14273, 13844, 13780, 13724, 13597, 13150, 13076, 13014, 12822, 12649,
38+
12428, 12335, 12242, 12160, 12110, 11872, 11864, 11838, 11787, 11561,
39+
11497, 11260, 11199, 10993, 10697, 10585, 10397, 10311, 10231, 10180,
40+
10085, 10038, 9877, 9738, 9690, 9611, 9466, 9447, 9434, 9357,
41+
9328, 9290, 9247, 9141, 8889, 8868, 8675, 8656, 8501, 8474,
42+
8371, 8333, 8327, 8312, 8250, 8190, 8188, 8154, 8033, 7984,
43+
8868, 8703, 8675, 8656, 8501, 8474, 8371, 8364, 8333, 8327,
44+
8312, 8250, 8211, 8190, 8188, 8154, 8033, 7984, 7967, 7928,
45+
7859, 7830, 7773, 7745, 7665, 7663, 7585, 7523, 7506, 7427,
46+
7401, 7388, 7376, 7372, 7280, 7232, 7227, 7104, 7060, 7002,
47+
6939, 6922, 6900, 6899, 6810, 6805, 6757, 6711, 6672, 6653,
48+
6411, 6406, 6354, 6305, 6294, 6229, 6225, 6216, 6160, 6069,
49+
6066, 6039, 6033, 6023, 5981, 5980, 5962, 5857, 5838, 5833,
50+
5800, 5769, 5736, 5725, 5697, 5676, 5663, 5642, 5625, 5580,
51+
5542, 5522, 5512, 5503, 5485, 5480, 5478, 5473, 5468, 5444,
52+
5395, 5390, 5327, 5255, 5250, 5227, 5203, 5176, 5156, 5151,
53+
4975, 4949, 4945, 4897, 4884, 4859, 4841, 4834, 4776, 4767,
54+
4765, 4756, 4739, 4736, 4727, 4704, 4686, 4668, 4666, 4644,
55+
4623, 4609, 4579, 4540, 4478, 4474, 4442, 4413, 4409, 4398,
56+
4382, 4367, 4315, 4276, 4271, 4257, 4238, 4228, 4224, 4220,
57+
4169, 4162, 4151, 4150, 4150, 4150, 4144, 4143, 4126, 4114,
58+
4088, 4085, 4077, 4043, 4028, 4017, 4013, 4011, 4008, 3997,
59+
3979, 3963, 3955, 3936, 3934, 3925, 3923, 3889, 3883, 3871,
60+
3859, 3831, 3824, 3814, 3809, 3805, 3754, 3717, 3709, 3704,
61+
3701, 3701, 3696, 3686, 3682, 3644, 3640, 3636, 3628, 3625,
62+
3601, 3587, 3558, 3531, 3523, 3516, 3508, 3508, 3508, 3503,
63+
3705, 3701, 3696, 3686, 3682, 3644, 3641, 3636, 3628, 3625,
64+
3601, 3587, 3558, 3531, 3528, 3523, 3516, 3508, 3508, 3508,
65+
3503, 3493, 3487, 3469, 3466, 3464, 3443, 3437, 3431, 3426,
66+
3417, 3393, 3389, 3364, 3364, 3361, 3359, 3350, 3342, 3332,
67+
3330, 3324, 3319, 3313, 3305, 3288, 3288, 3268, 3261, 3259,
68+
3239, 3228, 3224, 3221, 3203, 3200, 3189, 3187, 3183, 3180,
69+
3176, 3168, 3163, 3150, 3134, 3127, 3123, 3122, 3099, 3088,
70+
3080, 3079, 3076, 3072, 3068, 3039, 3036, 3019, 3017, 3010,
71+
2996, 2996, 2988, 2984, 2975, 2965, 2958, 2943, 2937, 2937,
72+
2926, 2920, 2913, 2896, 2884, 2882, 2871, 2867, 2867, 2849,
73+
2844, 2841, 2836, 2835, 2828, 2822, 2819, 2814, 2809, 2808,
74+
2795, 2792, 2787, 2784, 2778, 2774, 2773, 2772, 2770, 2762,
75+
2763, 2760, 2758, 2750, 2748, 2747, 2745, 2726, 2720, 2719,
76+
2699, 2693, 2690, 2673, 2671, 2668, 2652, 2651, 2649, 2647,
77+
2646, 2637, 2636, 2629, 2626, 2619, 2618, 2618, 2618, 2603,
78+
2600, 2588, 2563, 2560, 2558, 2542, 2538, 2538, 2529, 2528,
79+
2519, 2517, 2516, 2514, 2506, 2501, 2500, 2499, 2499, 2497,
80+
2488, 2485, 2483, 2482, 2473, 2446, 2437, 2427, 2424, 2413,
81+
2405, 2404, 2403, 2402, 2395, 2386, 2379, 2377, 2374, 2369,
82+
2367, 2362, 2360, 2358, 2355, 2355, 2353, 2347, 2341, 2338,
83+
2198, 2197, 2196, 2190, 2190, 2190, 2189, 2188, 2186, 2185,
84+
2182, 2178, 2176, 2172, 2169, 2166, 2162, 2161, 2154, 2153,
85+
2149, 2149, 2146, 2137, 2136, 2121, 2117, 2116, 2111, 2106,
86+
2106, 2104, 2103, 2100, 2099, 2098, 2094, 2093, 2087, 2084,
87+
2081, 2078, 2078, 2065, 2065, 2065, 2064, 2064, 2056, 2054,
88+
2050, 2043, 2042, 2038, 2024, 2018, 2010, 2008, 2006, 2001,
89+
1993, 1992, 1989, 1986, 1980, 1978, 1975, 1963, 1960, 1956,
90+
1951, 1950, 1948, 1946, 1940, 1937, 1935, 1932, 1929, 1927,
91+
1914, 1914, 1913, 1910, 1909, 1904, 1899, 1898, 1897, 1889,
92+
1886, 1880, 1874, 1874, 1866, 1865, 1862, 1860, 1858, 1854,
93+
1956, 1956, 1951, 1950, 1948, 1946, 1940, 1936, 1937, 1935,
94+
1932, 1929, 1927, 1914, 1914, 1913, 1910, 1909, 1904, 1899,
95+
1898, 1897, 1892, 1889, 1886, 1886, 1880, 1874, 1874, 1866,
96+
1865, 1862, 1860, 1858, 1854, 1851, 1848, 1847, 1847, 1844,
97+
1844, 1842, 1840, 1839, 1839, 1826, 1823, 1821, 1821, 1815,
98+
1813, 1805, 1801, 1798, 1797, 1796, 1788, 1786, 1784, 1783,
99+
1781, 1779, 1779, 1775, 1772, 1771, 1768, 1767, 1761, 1748,
100+
1745, 1746, 1739, 1739, 1736, 1736, 1732, 1730, 1724, 1724,
101+
1723, 1720, 1720, 1716, 1706, 1705, 1704, 1704, 1703, 1701,
102+
1700, 1695, 1694, 1693, 1687, 1684, 1683, 1683, 1683, 1682,
103+
1682, 1680, 1675, 1675, 1675, 1675, 1674, 1674, 1674, 1670,
104+
1669, 1665, 1664, 1658, 1658, 1657, 1655, 1651, 1650, 1649,
105+
1648, 1648, 1647, 1647, 1647, 1645, 1640, 1640, 1639, 1637,
106+
1632, 1630, 1630, 1627, 1624, 1624, 1620, 1620, 1616, 1614,
107+
1613, 1613, 1612, 1612, 1611, 1610, 1610, 1609, 1608, 1607,
108+
1606, 1606, 1604, 1604, 1602, 1602, 1601, 1599, 1598, 1597,
109+
1595, 1594, 1592, 1591, 1589, 1585, 1578, 1576, 1575, 1574,
110+
1574, 1569, 1569, 1568, 1567, 1567, 1567, 1566, 1565, 1563,
111+
1557, 1555, 1555, 1553, 1547, 1544, 1543, 1542, 1541, 1532,
112+
1530, 1529, 1528, 1527, 1525, 1523, 1519, 1515, 1515, 1514,
113+
1351, 1350, 1349, 1349, 1348, 1347, 1345, 1332, 1327, 1326,
114+
1323, 1323, 1322, 1321, 1319, 1319, 1317, 1317, 1315, 1314,
115+
1314, 1313, 1312, 1312, 1309, 1309, 1309, 1307, 1306, 1305,
116+
1305, 1304, 1303, 1303, 1302, 1300, 1299, 1299, 1299, 1297,
117+
1297, 1296, 1292, 1292, 1291, 1286, 1284, 1284, 1283, 1280,
118+
1279, 1278, 1278, 1277, 1276, 1276, 1273, 1273, 1267, 1266,
119+
1265, 1264, 1264, 1263, 1260, 1259, 1259, 1259, 1258, 1254,
120+
1253, 1250, 1250, 1248, 1247, 1246, 1244, 1241, 1240, 1240,
121+
1239, 1239, 1239, 1238, 1238, 1235, 1235, 1234, 1234, 1233,
122+
1232, 1232, 1229, 1228, 1228, 1225, 1220, 1218, 1217, 1211,
123+
1348, 1347, 1345, 1336, 1332, 1327, 1327, 1326, 1324, 1323,
124+
1323, 1322, 1321, 1319, 1319, 1317, 1317, 1315, 1315, 1314,
125+
1313, 1312, 1312, 1309, 1309, 1309, 1307, 1306, 1306, 1305,
126+
1305, 1304, 1303, 1303, 1302, 1301, 1299, 1299, 1299, 1298,
127+
1297, 1297, 1296, 1292, 1292, 1291, 1287, 1284, 1284, 1283,
128+
1281, 1280, 1280, 1280, 1278, 1278, 1278, 1276, 1276, 1273,
129+
1273, 1267, 1267, 1265, 1264, 1264, 1263, 1260, 1259, 1259,
130+
1259, 1258, 1254, 1253, 1251, 1251, 1250, 1248, 1247, 1246,
131+
1244, 1241, 1240, 1240, 1239, 1239, 1239, 1238, 1238, 1236,
132+
1235, 1235, 1234, 1234, 1234, 1233, 1232, 1232, 1229};
133+
}

0 commit comments

Comments
 (0)