Skip to content

Commit b4a00b7

Browse files
authored
Merge pull request #7911 from bdach/osu-matplotlib-theme
Add matplotlib theme for creating graphs for newsposts and wiki articles
2 parents c8c89bf + 7a52c75 commit b4a00b7

File tree

8 files changed

+479
-0
lines changed

8 files changed

+479
-0
lines changed

meta/osu-matplotlib-theme/README.ipynb

+199
Large diffs are not rendered by default.

meta/osu-matplotlib-theme/README.md

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!-- This Markdown file was autogenerated from README.ipynb using the generate_readme.sh script. DO NOT MODIFY THIS FILE DIRECTLY. -->
2+
3+
# `osu-matplotlib-theme`
4+
5+
This directory contains theme files to be used with the Python plotting library [matplotlib](https://matplotlib.org/). The themes are adapted to visually match the style of published article pages on the [osu! website](https://osu.ppy.sh/home).
6+
7+
The files here are mostly intended to be used by developers of star rating and performance points algorithms used in osu! who may wish to better convey technical changes in the aforementioned algorithms using graphs inlined into development articles.
8+
9+
Additionally, a second theme is also provided, which matches the appearance of the osu! wiki, allowing creation of graphs for wiki articles with matplotlib.
10+
11+
Theme files contained within are based on graphs previously embedded in articles describing changes to star rating/performance points algorithms:
12+
13+
* [Performance Points Updates (Jan 2021)](https://osu.ppy.sh/home/news/2021-01-14-performance-points-updates)
14+
* [Performance Points & Star Rating Updates (Jul 2021)](https://osu.ppy.sh/home/news/2021-07-27-performance-points-star-rating-updates)
15+
* [Performance Points & Star Rating Updates (Nov 2021)](https://osu.ppy.sh/home/news/2021-11-09-performance-points-star-rating-updates)
16+
17+
The repository contains the following main files:
18+
19+
* `.mplstyle` files: matplotlib [style sheets](https://matplotlib.org/stable/tutorials/introductory/customizing.html) that apply most of boilerplate styling you may need. The following variants are included:
20+
- `osu-news.mplstyle` is intended to be used for graphs on newsposts,
21+
- `osu-wiki.mplstyle` is intended to be used for graphs on wiki articles.
22+
23+
* `osu_cmap.py`: a python script declaring a matplotlib discrete [colour map](https://matplotlib.org/stable/tutorials/colors/colormaps.html) that you can use to colour data series with.
24+
25+
Both files intend to match the osu! website design language.
26+
27+
To use these themes, you will obviously need to install matplotlib. Data manipulation packages such as [numpy](https://numpy.org/) or [pandas](https://pandas.pydata.org/) may also come in handy:
28+
29+
30+
```python
31+
import matplotlib.pyplot as plt
32+
import numpy as np
33+
import pandas as pd
34+
```
35+
36+
Additionally, the theme uses the [Inter](https://rsms.me/inter/) font for displaying textual content. Please make sure you have a system-wide installation of the font in question, or otherwise graphs may not look as intended.
37+
38+
## Usage examples
39+
40+
### Simple X-Y line plot
41+
42+
43+
```python
44+
# generate some fake data to plot
45+
xs = np.linspace(0, 4 * np.pi, 1000)
46+
ys = xs * np.sin(xs)
47+
zs = np.sqrt(xs) * np.cos(xs)
48+
49+
# import and use the colormap
50+
from osu_cmap import OSU_CMAP
51+
plt.rcParams["axes.prop_cycle"] = plt.cycler("color", OSU_CMAP.colors)
52+
53+
# use the theme
54+
# note that this is being used in a `with` block to provide temporary styling
55+
# (https://matplotlib.org/stable/tutorials/introductory/customizing.html#temporary-styling)
56+
with plt.style.context('./osu-news.mplstyle'):
57+
plt.plot(xs, ys)
58+
plt.plot(xs, zs)
59+
60+
plt.title('Example plot')
61+
plt.xlabel('X axis')
62+
plt.ylabel('Y axis')
63+
plt.legend(['Series 1', 'Series 2'])
64+
65+
plt.show()
66+
```
67+
68+
69+
70+
![png](README_files/README_6_0.png)
71+
72+
73+
74+
### Bar plot with more complications
75+
76+
77+
```python
78+
# generate some fake data to plot
79+
xs = range(10)
80+
category_count = 7
81+
82+
# import and use the colormap
83+
from osu_cmap import OSU_CMAP
84+
plt.rcParams["axes.prop_cycle"] = plt.cycler("color", OSU_CMAP.colors)
85+
86+
# use the theme
87+
# note that this is being used in a `with` block to provide temporary styling
88+
# (https://matplotlib.org/stable/tutorials/introductory/customizing.html#temporary-styling)
89+
with plt.style.context('./osu-wiki.mplstyle'):
90+
bottom = np.zeros(10)
91+
92+
# plot some fake data
93+
for i in range(category_count):
94+
ys = np.random.rand(len(xs))
95+
plt.bar(xs, ys, bottom=bottom, zorder=i+2)
96+
bottom += ys
97+
98+
plt.title('Example plot')
99+
plt.xlabel('X axis')
100+
plt.ylabel('Y axis')
101+
# even though the style does most of the job, sometimes stuff needs to be jiggled to work
102+
# (in this case we're putting the legend outside of the plot)
103+
plt.legend([f'Series {i+1}' for i in range(category_count)],
104+
bbox_to_anchor=(1.03, 1),
105+
loc='upper left')
106+
107+
plt.show()
108+
```
109+
110+
111+
112+
![png](README_files/README_8_0.png)
113+
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# This script generates a Markdown file from the README.ipynb Jupyter notebook.
4+
# Normally, the hope is that the Jupyter notebook would be enough, since GitHub can render it,
5+
# but as it turns out, it doesn't render if it's used as a README in a directory,
6+
# but will render if _and only if_ the individual file is opened
7+
# (see: https://github.com/github/markup/issues/929)
8+
# Hence, we make do with what we have and we convert to markdown for readers' convenience.
9+
#
10+
# This script requires jupyter to be installed on your machine.
11+
12+
set -e
13+
14+
jupyter nbconvert --execute --to markdown README.ipynb
15+
printf '%s\n\n%s' "<!-- This Markdown file was autogenerated from README.ipynb using the generate_readme.sh script. DO NOT MODIFY THIS FILE DIRECTLY. -->" "$(cat README.md)" > README.md
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# osu! matplotlib theme
2+
# News variant
3+
4+
#-------------------------------------------------------------------------------
5+
# Font
6+
#-------------------------------------------------------------------------------
7+
8+
font.family: Inter
9+
font.size: 16
10+
11+
#-------------------------------------------------------------------------------
12+
# Figure
13+
#-------------------------------------------------------------------------------
14+
15+
figure.facecolor: 24222a
16+
figure.figsize: 10, 6
17+
18+
figure.constrained_layout.use: True
19+
20+
#-------------------------------------------------------------------------------
21+
# Axes
22+
#-------------------------------------------------------------------------------
23+
24+
axes.facecolor: 24222a
25+
26+
axes.titlecolor: white
27+
axes.titlesize: 24
28+
axes.titlepad: 20
29+
30+
axes.labelcolor: white
31+
axes.labelpad: 10
32+
33+
axes.edgecolor: white
34+
axes.spines.bottom: True
35+
axes.spines.left: True
36+
axes.spines.right: False
37+
axes.spines.top: False
38+
39+
axes.grid: True
40+
41+
#-------------------------------------------------------------------------------
42+
# X ticks
43+
#-------------------------------------------------------------------------------
44+
45+
xtick.color: white
46+
xtick.labelcolor: white
47+
48+
#-------------------------------------------------------------------------------
49+
# Y ticks
50+
#-------------------------------------------------------------------------------
51+
52+
ytick.color: white
53+
ytick.labelcolor: white
54+
55+
#-------------------------------------------------------------------------------
56+
# Grid
57+
#-------------------------------------------------------------------------------
58+
59+
grid.color: 3d3946
60+
61+
#-------------------------------------------------------------------------------
62+
# Legend
63+
#-------------------------------------------------------------------------------
64+
65+
legend.facecolor: 3d3946
66+
legend.edgecolor: 3d3946
67+
legend.labelcolor: white
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# osu! matplotlib theme
2+
# Wiki variant
3+
4+
#-------------------------------------------------------------------------------
5+
# Font
6+
#-------------------------------------------------------------------------------
7+
8+
font.family: Inter
9+
font.size: 16
10+
11+
#-------------------------------------------------------------------------------
12+
# Figure
13+
#-------------------------------------------------------------------------------
14+
15+
figure.facecolor: 2a2822
16+
figure.figsize: 10, 6
17+
18+
figure.constrained_layout.use: True
19+
20+
#-------------------------------------------------------------------------------
21+
# Axes
22+
#-------------------------------------------------------------------------------
23+
24+
axes.facecolor: 2a2822
25+
26+
axes.titlecolor: white
27+
axes.titlesize: 24
28+
axes.titlepad: 20
29+
30+
axes.labelcolor: white
31+
axes.labelpad: 10
32+
33+
axes.edgecolor: white
34+
axes.spines.bottom: True
35+
axes.spines.left: True
36+
axes.spines.right: False
37+
axes.spines.top: False
38+
39+
axes.grid: True
40+
41+
#-------------------------------------------------------------------------------
42+
# X ticks
43+
#-------------------------------------------------------------------------------
44+
45+
xtick.color: white
46+
xtick.labelcolor: white
47+
48+
#-------------------------------------------------------------------------------
49+
# Y ticks
50+
#-------------------------------------------------------------------------------
51+
52+
ytick.color: white
53+
ytick.labelcolor: white
54+
55+
#-------------------------------------------------------------------------------
56+
# Grid
57+
#-------------------------------------------------------------------------------
58+
59+
grid.color: 38362e
60+
61+
#-------------------------------------------------------------------------------
62+
# Legend
63+
#-------------------------------------------------------------------------------
64+
65+
legend.facecolor: 38362e
66+
legend.edgecolor: 38362e
67+
legend.labelcolor: white

meta/osu-matplotlib-theme/osu_cmap.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
from matplotlib.colors import ListedColormap
4+
5+
6+
COLORS = \
7+
[
8+
[255, 102, 171],
9+
[140, 102, 255],
10+
[102, 204, 255],
11+
[102, 255, 115],
12+
[178, 255, 102],
13+
[255, 217, 102],
14+
[255, 102, 102]
15+
]
16+
17+
18+
OSU_CMAP = ListedColormap(np.array(COLORS) / 255)

0 commit comments

Comments
 (0)