ソースを参照

Improve the churn plot

Vadim Markovtsev 7 年 前
コミット
797a31712f
2 ファイル変更8 行追加1 行削除
  1. 8 1
      contrib/_plugin_example/plot_churn.py
  2. BIN
      doc/churn_global.png

+ 8 - 1
contrib/_plugin_example/plot_churn.py

@@ -7,6 +7,7 @@ import yaml
 
 from matplotlib import pyplot
 import matplotlib.dates as mdates
+import numpy
 import pandas
 
 
@@ -48,6 +49,11 @@ def plot_churn(name, data, url, beginTime, endTime, output, fmt, tick_interval):
                           columns=("additions", "removals"))
     df["removals"] = -df["removals"]
     df = df.reindex(pandas.date_range(beginTime, endTime, freq="D"))
+    effective = df["additions"] + df["removals"]
+    effective = effective.cumsum()
+    effective.fillna(method="ffill", inplace=True)
+    scale = numpy.maximum(df.max(), -df.min()).max()
+    effective = effective / effective.max() * scale
     pyplot.figure(figsize=(16, 9))
     for spine in pyplot.gca().spines.values():
         spine.set_visible(False)
@@ -56,8 +62,9 @@ def plot_churn(name, data, url, beginTime, endTime, output, fmt, tick_interval):
     pyplot.tick_params(top="off", bottom="off", left="off", right="off", labelleft="off", labelbottom="on")
     pyplot.bar(df.index, df["additions"], label="additions")
     pyplot.bar(df.index, df["removals"], label="removals")
+    pyplot.plot(df.index, effective, "black", label="effective")
     pyplot.xticks(rotation="vertical")
-    pyplot.legend(loc=1)
+    pyplot.legend(loc=2, fontsize=18)
     pyplot.title("%s churn plot, %s" % (name, url), fontsize=24)
     if not output:
         pyplot.show()

BIN
doc/churn_global.png