python matplotlib情节

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python matplotlib情节相关的知识,希望对你有一定的参考价值。

def autolabel(rects):
    """
    Attach a text label above each bar displaying its height
    """
    for rect in rects:
        height = rect.get_height()
        ax.text(
            rect.get_x() + rect.get_width()/2.,
            1.01*height,
            s='%.4f' % height,
            ha='center',
            va='bottom',
        )

fig, ax = plt.subplots(figsize=(12, 7))
width = 0.35
bar_plot = ax.bar(scores_for_plot, results, width, color='g')
autolabel(bar_plot)
plt.title('1 - math.sqrt(abs_diff / max_score)', size=20, color='k')
plt.show()
def autolabel(rects):
    """
    Attach a text label above each bar displaying its height
    """
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
                '%.2f' % height,
                ha='center', va='bottom')


ind = np.arange(len(df_analysis))
width = 0.35

fig, ax = plt.subplots(figsize=(12, 7))

inet_presence = ax.bar(ind, df_analysis['inet_presence_share'], width, color='g', yerr=df_analysis['margin_of_error'])
es_presence = ax.bar(ind + width, analysis_es['share'], width, color='y')

ax.set_xticks(ind + width/2)
ax.set_xticklabels(df_analysis['label'], rotation='vertical', size=11, color='k')
ax.yaxis.grid(True, color='k', linewidth=.5)

plt.title('Internet presence vs. ES presence (Denmark)', size=20, color='k')
plt.yticks(color='k')

autolabel(inet_presence)
autolabel(es_presence)

ax.legend((inet_presence[0], es_presence[0]), ('Inet presence', 'ES presence'))

plt.show()
def draw_histogram(
    df,
    var,
    label,
    bins=50,
    xlim=None,
    normed=False,
):  
  
    fig, axes = plt.subplots(1, 1, figsize=(8, 5))
    axes.hist(df[var][df[label] == 0], bins=bins, normed=normed, label='negative', alpha=.7, range=xlim)
    axes.hist(df[var][df[label] == 1], bins=bins, normed=normed, label='positive', alpha=.7, range=xlim)
    axes.legend()
    axes.set_title(var)
fig, axes = plt.subplots(1, 1, figsize=(9, 5))
axes.plot(num_obs_acc, f_score_acc)
axes.grid()
axes.set_title('F-score for fixed test set over num nodes in training set')
axes.set_xlabel('num nodes')
axes.set_ylabel('f-score')
plt.show()

以上是关于python matplotlib情节的主要内容,如果未能解决你的问题,请参考以下文章

Python matplotlib,图上的时间戳

自动保存绘图、python、matplotlib

Matplotlib 扩大情节

matplotlib交换x和y轴

如何使用 matplotlib 在 Python 中创建图例

如何在 Matplotlib 的子图中独立绘制相同的图形? [复制]