濮阳杆衣贸易有限公司

主頁 > 知識庫 > python 如何設置柱狀圖參數(shù)

python 如何設置柱狀圖參數(shù)

熱門標簽:池州外呼調(diào)研線路 江西省地圖標注 如何申請400電話費用 沈陽人工外呼系統(tǒng)價格 富錦商家地圖標注 武漢外呼系統(tǒng)平臺 沈陽防封電銷卡品牌 外呼系統(tǒng)哪些好辦 沈陽外呼系統(tǒng)呼叫系統(tǒng)

version:python 3.6

環(huán)境:anaconda/JupyterLab 0.27.0

操作系統(tǒng):Windows 10

import pandas as pd
import matplotlib.pyplot as plt
a = pd.DataFrame(train_set['收率'].value_counts()).reset_index()
a.rename(columns={'index': 'yield','收率':'frequency'}, inplace=True)
a.head()
plt.figure(figsize=(24,8))
plt.bar(a['yield'].values,a['frequency'].values.round(2),color='rgb',width = 0.005,
tick_label=a['yield'].values.round(3))
plt.xlabel('yield', fontsize=20)
plt.ylabel('frequency', fontsize=20)
plt.show()

補充:python 用 matplotlib 繪制柱狀圖參數(shù)詳解 plt.bar()

1、加載庫

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

2 繪圖,逐步設置 bar() 參數(shù)

def title_table(ax):
    '''為圖表添加標題和表格'''
    ax.set_title(label=f'No.{i+1}',
                loc='center',
                pad=None,
                fontdict={'color': 'b'}
                 )
    ax.table(loc='upper right',    # 表格在圖表區(qū)的位置
          
          colLabels=[f'{i+2} args'],    # 表格每列的列名稱
          colColours=['g'],    # 表格每列列名稱所在單元格的填充顏色
          colLoc='left',    # 表格中每列列名稱的對齊位置
          colWidths=[0.15],    # 表格每列的寬度         
          cellText=args,    # 表格中的數(shù)值, 每行數(shù)據(jù)的列表的列表
          cellColours=[['cornsilk']]*len(args),    # 表格中數(shù)據(jù)所在單元格的填充顏色
          cellLoc='left',    # 表格中數(shù)據(jù)的對齊位置
          fontsize=8)
# 配置字體,顯示中文
mpl.rcParams['font.sans-serif'] = ['SimHei']  
# 配置坐標軸刻度值模式,顯示負號
mpl.rcParams['axes.unicode_minus'] = True
# 定義數(shù)據(jù)
x = [1, 2, 3, 4, 5]
y = [6, 10, 4, 5, 1]
labels = list('ABCDE')
                   
fig, axes = plt.subplots(nrows=3,
                         ncols=3,
                         sharex=True,
                         sharey=True,
                         figsize=(18, 20),
                         facecolor='cornsilk')
axes = axes.ravel()
i = 0
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
       )
args = [[e] for e in ['x', 'height']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
i = 1
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
        align='edge',    #  x 軸上的坐標與柱體對其的位置
       )
args = [[e] for e in ['x', 'height', 'align']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
i = 2
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
        align='edge',    #  x 軸上的坐標與柱體對其的位置
        color='c',    # 柱體的填充顏色
        )
args = [[e] for e in ['x', 'height', 'align', 'color']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
i = 3
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
        align='edge',    #  x 軸上的坐標與柱體對齊的位置
        color='cyan',    # 柱體的填充顏色
        tick_label=labels,    # 每個柱體的標簽名稱
        )
args = [[e] for e in ['x', 'height', 'align', 'color', 'tick_label']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
i = 4
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
        align='edge',    #  x 軸上的坐標與柱體對其的位置
        color='blue',    # 柱體的填充顏色
        tick_label=labels,    # 每個柱體的標簽名稱
        alpha=0.6    # 柱體填充顏色的透明度
        )
args = [[e] for e in ['x', 'height', 'align', 'color', 'tick_label', 'alpha']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
i = 5
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
        align='edge',    #  x 軸上的坐標與柱體對其的位置
        color='wheat',    # 柱體的填充顏色
        tick_label=labels,    # 每個柱體的標簽名稱
        alpha=0.6,    # 柱體填充顏色的透明度
        width=1,  # 柱體的寬度
        )
args = [[e] for e in ['x', 'height', 'align', 'color', 'tick_label', 'alpha', 'width']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
i = 6
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
        align='edge',    #  x 軸上的坐標與柱體對其的位置
        color='aqua',    # 柱體的填充顏色
        tick_label=labels,    # 每個柱體的標簽名稱
        alpha=0.6,    # 柱體填充顏色的透明度
        width=0.8,    # 柱體的寬度
        bottom=0.2,     # 柱體基線的 y 軸坐標
        )
args = [[e] for e in ['x', 'height', 'align', 'color', 'tick_label', 'alpha', 'width',
                      'bottom']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
i = 7
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
        align='edge',    #  x 軸上的坐標與柱體對其的位置
        color='lightpink',    # 柱體的填充顏色
        tick_label=labels,    # 每個柱體的標簽名稱
        alpha=0.6,    # 柱體填充顏色的透明度
        width=0.8,    # 柱體的寬度
        bottom=0.2,    # 柱體基線的 y 軸坐標
        edgecolor='g'   # 柱體的邊框顏色
        )
args = [[e] for e in ['x', 'height', 'align', 'color', 'tick_label', 'alpha', 'width',
                      'bottom', 'edgecolor']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
i = 8
ax = axes[i]
# 繪制柱狀圖
ax.bar(x=x,    # 柱體在 x 軸上的坐標位置
        height=y,    # 柱體的高度
        align='center',    #  x 軸上的坐標與柱體對其的位置
        color='bisque',    # 柱體的填充顏色
        tick_label=labels,    # 每個柱體的標簽名稱
        alpha=0.6,    # 柱體填充顏色的透明度
        width=0.8,    # 柱體的寬度
        bottom=0.2,    # 柱體基線的 y 軸坐標
        edgecolor='g',   # 柱體的邊框顏色
        linewidth=1.5,   # 柱體邊框線的寬度
        )
args = [[e] for e in ['x', 'height', 'align', 'color', 'tick_label', 'alpha', 'width',
                      'bottom', 'edgecolor', 'linewidth']]
# 向圖表子區(qū)添加標題和數(shù)據(jù)表
title_table(ax)
# 設置整個子區(qū)的布局
fig.subplots_adjust(left=0,
                    bottom=0,
                    right=0.9,
                    top=1,
                    wspace=0.1,    # 子區(qū)間空白區(qū)域的寬度的歸一化值
                    hspace=0.2);    # 子區(qū)間空白區(qū)域的高度的歸一化值

圖表

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Python利用imshow制作自定義漸變填充柱狀圖(colorbar)
  • Python3 pyecharts生成Html文件柱狀圖及折線圖代碼實例
  • Python matplotlib模塊及柱狀圖用法解析
  • python 畫條形圖(柱狀圖)實例
  • Python數(shù)據(jù)可視化處理庫PyEcharts柱狀圖,餅圖,線性圖,詞云圖常用實例詳解
  • python plotly畫柱狀圖代碼實例

標簽:銅川 阿里 株洲 通遼 常德 潛江 呂梁 黑龍江

巨人網(wǎng)絡通訊聲明:本文標題《python 如何設置柱狀圖參數(shù)》,本文關鍵詞  python,如何,設置,柱狀,圖,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關。
  • 相關文章
  • 下面列出與本文章《python 如何設置柱狀圖參數(shù)》相關的同類信息!
  • 本頁收集關于python 如何設置柱狀圖參數(shù)的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    龙井市| 仪陇县| 阿克| 开封县| 昭苏县| 辽宁省| 保亭| 遵义县| 红原县| 龙南县| 墨玉县| 乐山市| 泰州市| 武平县| 阳西县| 东阿县| 扎鲁特旗| 县级市| 安徽省| 临海市| 修武县| 潮州市| 建始县| 西林县| 梨树县| 河西区| 太白县| 本溪市| 杭锦旗| 泰兴市| 黄陵县| 平武县| 望城县| 大同市| 桂林市| 三门县| 云梦县| 靖宇县| 武胜县| 陈巴尔虎旗| 西峡县|