In [4]:
from IPython.display import display
from PIL import Image
In [ ]:
 
In [ ]:
 
In [ ]:
 

Bar plot axis diagonal label

import matplotlib.pyplot as plt
%matplotlib inline

tdf = tdf.sort_values("date")
display(tdf.head())
#tdf.sort_values("date").set_index("date").tail(15).plot(kind='bar',figsize=(22,6),rot=45)
fig, ax = plt.subplots()
fig.set_size_inches(14,6)
def parse(x):
    a,b = x.split("_")
    return "{}_{}".format(b, toil.getsptime(b).strftime("%Y-%b-%d"))
bkids2 = [i.split("_")[1] for i in bkids]
lastk = 0
customticks = []
x = list(tdf["backupid"].apply(parse))
for k,tick in enumerate(x):
    l,r = tick.split("_")
    if l in bkids2:
        lastk = k
        customticks.append(tick)
    elif k == 0:
        customticks.append(tick)
    elif k == len(x)-1:
        customticks.append(tick)
    elif k%9==0 and abs(k-lastk) > 6:
        if "2485" in tick:
            customticks.append("")
        else:
            customticks.append(tick)
    else:
        customticks.append("")

print(x)
ax.bar(x, list(tdf["disksize (KB)"].values))
ax.set_xticklabels(customticks)
#ax.tick_params(which='both', width=2)
ax.tick_params(which='major', length=7)
ax.tick_params(axis="x", labelsize=12) 
ax.set_title("Disk2")
for label in ax.get_xmajorticklabels() + ax.get_xmajorticklabels():
    label.set_rotation(30)
    label.set_horizontalalignment("right")
In [6]:
display(Image.open('img1.png'))

Pandas Bar plot label

maxval = gdf_ms['x'].max()
ax = gdf_ms.set_index("x").plot.bar(color='#305496', figsize=(17,6))
a = ax.set_xticklabels(ax.get_xticklabels(), rotation=45, horizontalalignment='right')
for p in ax.patches:
    ax.annotate(str(int(p.get_height())), (p.get_x() + p.get_width()/2, p.get_height() * 1.005),
               xytext=(0,10), textcoords='offset points', horizontalalignment='center', va='center', size=20)
plt.xlabel('x', fontsize=18)
plt.ylabel('y', fontsize=18)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
ax.get_legend().remove()
ax.set_ylim(0,maxval+50)
In [9]:
display(Image.open('img2.png'))

Sparkline print

size = len(ck)
#size = 10
fig, ax = plt.subplots(size, sharex=True, sharey=True, gridspec_kw={'hspace': 0})
fig.set_size_inches(18,size)
for index in range(size):
    i = ck[index]
    if not i in appd_bt_calls: continue
    _tdf = appd_bt_calls[i] 
    _tdf["ds"] = _tdf["ds"].dt.tz_localize(None)
    if fit is not None:
        rows = _tdf.to_dict(orient='records')
        for k,v in b.iteritems():
            rows.append({"ds": v, "y": np.nan})
    ax[index].plot(_tdf["ds"].values, _tdf["y"].values, label=i)
    ax[index].legend(loc='upper right', bbox_to_anchor=(1.35, 1))
plt.show()
In [11]:
display(Image.open("img3.png"))
In [ ]:
 

Line Plot Many

def plotcalls(pod_names, fit=None):
    fig, ax = plt.subplots()
    fig.set_size_inches(18,6)
    for i in pod_names:
        if not i in appd_bt_calls: continue
        _tdf = appd_bt_calls[i] 
        if fit is not None:
            rows = _tdf.to_dict(orient='records')
            for k,v in b.iteritems():
                rows.append({"ds": v, "y": None})
            _tdf = pd.DataFrame(rows)
            _tdf = _tdf.drop_duplicates()
            _tdf["ds"] = pd.to_datetime(_tdf["ds"].apply(lambda x: x.timestamp()), unit='s', utc=True)
            _tdf = _tdf.sort_values("ds").reset_index(drop=True)
            _tdf["y"] = _tdf["y"].interpolate()
            _tdf = _tdf[_tdf["ds"].isin(fit.values)].reset_index(drop=True)
            _tdf = _tdf.replace(float('nan'), 0)

        ax.plot(_tdf["ds"].values, _tdf["y"].values, label=i)
    ax.legend(loc='upper right', bbox_to_anchor=(1.4, 1))
    plt.show()
plotcalls(ck[:10])
In [14]:
display(Image.open("img4.png"))
In [ ]:
 

Dual axis plot

import matplotlib.pyplot as plt

def savefig(gdf, save_fig_path=""):
    fig, ax = plt.subplots()
    fig.set_size_inches(17,5)
    l = "#7496ec"
    r = "#f985bd"
    ax.plot(gdf["ds"].values, gdf["cpu"].values, color=l, label="cpu (ms)")
    ax2 = ax.twinx()
    ax2.plot(gdf["ds"].values, gdf["calls"].values, color=r, label='calls')
    ax.legend(loc=2)
    ax2.legend(loc=0)
    ax.tick_params(axis='y', colors=l)
    ax2.tick_params(axis='y', colors=r)
    fig.tight_layout()
    if save_fig_path == "":
        fig.savefig(save_fig_path)
    else:
        plt.show()
savefig(gdf)
In [16]:
display(Image.open("img5.png"))
In [ ]:
 

Bar plot from pandas

ax = tdf.set_index("ds").plot.bar(figsize=(17,6))
ax.xaxis.set_major_locator(plt.MaxNLocator(8))
s = ax.set_xticklabels(ax.get_xticklabels(), rotation=45, ha='right')
def myfmt(value, tick_number):
    value = int(value)
    if value >= 0 and value < len(tdf):
        return str(tdf['ds'].iloc[value].strftime('%Y-%m-%d'))
    return ""
ax.xaxis.set_major_formatter(plt.FuncFormatter(myfmt))
In [18]:
display(Image.open("img6.png"))
In [ ]:
 

Compare month's days

df = data.copy()
fig, ax = plt.subplots()
fig.set_size_inches(17,6)
gdf = pd.DataFrame()
for s in sel:
    df_ = df[df['ds']].apply(lambda x: s[0] == x.year and s[1] == x.month)
    df_ = df_.set_index('ds').resample("12h").mean().reset_index()
    #df_.set_index('ds').plot(figsize=(17,6))
    label = datetime.datetime.(*s, 1).strftime('%b %Y')
    #df_ = df_.rename(columns={'y': label})
    df_['ds'] = df_['ds'].apply(lambda x: x.replace(month=1))
    ax.plot(df_['ds'].values, df_['y'].values, label=label)
    ax.legend(loc='best')

date_fmt = mdates.DateFormatter('%d')
ax.xaxis.set_major_formatter(date_fmt)
plt.show()
In [21]:
display(Image.open("img7.png"))
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: