|
| 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 | + |
| 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 | + |
| 113 | + |
0 commit comments