Skip to content

Instantly share code, notes, and snippets.

@Fallen-Breath
Last active May 6, 2024 17:19
Show Gist options
  • Save Fallen-Breath/da87d76df3b5012ef1d93626dca96233 to your computer and use it in GitHub Desktop.
Save Fallen-Breath/da87d76df3b5012ef1d93626dca96233 to your computer and use it in GitHub Desktop.
Draw wiske farm rates
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.family'] = 'Source Han Sans SC'
include_pre = False
data = {
'1.18.1': {'无游走': 6121, '普通方块游走': 6273, '地狱砖游走': 7205},
'1.18.2-pre1': {'无游走': 7576, '普通方块游走': 7603, '地狱砖游走': 7313},
'1.18.2-pre2': {'无游走': 6231, '普通方块游走': 6266, '地狱砖游走': 6199},
'1.18.2-pre3': {'无游走': 6010, '普通方块游走': 6151, '地狱砖游走': 5702},
'1.18.2': {'无游走': 6194, '普通方块游走': 6168, '地狱砖游走': 5637},
}
if not include_pre:
for key in list(data.keys()):
if '-pre' in key:
data.pop(key)
rows = []
for version, values in data.items():
for category, count in values.items():
rows.append({'version': version, 'category': category, 'rate': count})
df = pd.DataFrame(rows)
fig, ax = plt.subplots(figsize=(10 if include_pre else 6, 6), dpi=200)
bar_width = 0.2
index = np.arange(len(df['version'].unique()))
bar_colors = {'无游走': 'lightblue', '普通方块游走': 'y', '地狱砖游走': 'lightcoral'}
bar_shift = {'无游走': -1, '普通方块游走': 0, '地狱砖游走': 1}
for c, group in sorted(df.groupby('category', sort=False), key=lambda t: bar_shift[t[0]]):
cnt = group.groupby('version', sort=False)['rate'].sum()
bars = ax.bar(index + bar_width * bar_shift[c], cnt, bar_width, label=c, color=bar_colors[c])
for bar in bars:
ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height(), str(int(bar.get_height())), ha='center', va='bottom', rotation=0, fontsize=8 if include_pre else 10)
ax.legend(title='场景', loc='upper right')
ax.set_xticks(index)
ax.set_xticklabels(df['version'].unique())
ax.set_xlabel('MC版本')
ax.set_ylabel('凋灵骷髅/h')
plt.ylim(0, 8500)
plt.axhline(y=6100, color='gray', linestyle='--', linewidth=1)
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment