Hướng dẫn how do i plot two bar charts side by side in python? - làm cách nào để vẽ hai biểu đồ thanh cạnh nhau trong python?

Đôi khi có thể là khó khăn để tìm ra chiều rộng thanh phù hợp. Tôi thường sử dụng np.diff này để tìm đúng kích thước.

import numpy as np
import matplotlib.pyplot as plt

#The data
womenMeans = [25, 32, 34, 20, 25]
menMeans = [20, 35, 30, 35, 27]
indices = [5.5,6,7,8.5,8.9]
#Calculate optimal width
width = np.min[np.diff[indices]]/3


fig = plt.figure[]
ax = fig.add_subplot[111]
# matplotlib 3.0 you have to use align
ax.bar[indices-width,womenMeans,width,color='b',label='-Ymin',align='edge']
ax.bar[indices,menMeans,width,color='r',label='Ymax',align='edge']


ax.set_xlabel['Test histogram']
plt.show[]
# matplotlib 2.0 [you could avoid using align]
# ax.bar[indices-width,womenMeans,width,color='b',label='-Ymin']
# ax.bar[indices,menMeans,width,color='r',label='Ymax']

Đây là kết quả:

Điều gì sẽ xảy ra nếu các chỉ số của tôi trên trục X của tôi là các giá trị danh nghĩa như tên:

#
import numpy as np
import matplotlib.pyplot as plt

# The data
womenMeans = [25, 32, 34, 20, 25]
menMeans = [20, 35, 30, 35, 27]
indices = range[len[womenMeans]]
names = ['Asian','European','North Amercian','African','Austrailian','Martian']
# Calculate optimal width
width = np.min[np.diff[indices]]/3.

fig = plt.figure[]
ax = fig.add_subplot[111]
ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
#tiks = ax.get_xticks[].tolist[]
ax.axes.set_xticklabels[names]
ax.set_xlabel['Test histogram']
plt.show[]

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    ĐọcGrouped Bar chart. A Bar plot or a Bar Chart has many customizations such as Multiple bar plots, stacked bar plots, horizontal bar charts. Multiple bar charts are generally used for comparing different entities. In this article, plotting multiple bar charts are discussed.

    Bàn luậnSimple multiple bar chart

    Một biểu đồ nhiều thanh còn được gọi là biểu đồ thanh được nhóm. Một lô thanh hoặc biểu đồ thanh có nhiều tùy chỉnh như nhiều lô thanh, lô thanh xếp chồng, biểu đồ thanh ngang. Nhiều biểu đồ thanh thường được sử dụng để so sánh các thực thể khác nhau. Trong bài viết này, âm mưu nhiều biểu đồ thanh được thảo luận.

    Approach:

    1. Ví dụ 1: Biểu đồ nhiều thanh đơn giản
    2. Trong ví dụ này, chúng ta sẽ thấy cách vẽ nhiều biểu đồ thanh bằng matplotlib, ở đây chúng ta đang vẽ nhiều biểu đồ thanh để hình dung số lượng nam và nữ trong mỗi nhóm.
    3. Nhập các thư viện bắt buộc như Numpy để thực hiện các tính toán số với các mảng và matplotlib để trực quan hóa dữ liệu.
    4. Dữ liệu để vẽ nhiều biểu đồ thanh được đưa vào danh sách.
    5. Hàm np.arange [] từ thư viện Numpy được sử dụng để tạo ra một loạt các giá trị. Chúng tôi đang tạo các giá trị trục x tùy thuộc vào số lượng nhóm trong ví dụ của chúng tôi.
    6. Vẽ đồ thị nhiều thanh bằng hàm plt.bar [].
    7. Để tránh chồng chéo các thanh trong mỗi nhóm, các thanh được dịch chuyển -0.2 đơn vị và +0.2 đơn vị từ trục X.

    Code:

    Python3

    Chiều rộng của các thanh của mỗi nhóm được lấy là 0,4 đơn vị.

    Cuối cùng, nhiều bảng xếp hạng thanh cho cả nam và nữ được vẽ trong mỗi nhóm.

    import numpy as np 

    import matplotlib.pyplot as plt 

    X =

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    7= [import0____1010____222222222222

    import8= [import2222

    numpy as np 9= import1import2import3

    X 2

    X 3X 4matplotlib.pyplot as plt 2

    import4___

    X 9=0matplotlib.pyplot as plt 2

    =2

    =3

    import4matplotlib.pyplot as plt 4 import6matplotlib.pyplot as plt 6import8import9= X 0matplotlib.pyplot as plt 2

    X 6X 7matplotlib.pyplot as plt 2Number of Men and Women voted from 2018-2021

    Đầu ra:

    1. Ví dụ 1: Biểu đồ nhiều thanh đơn giản
    2. Trong ví dụ này, chúng ta sẽ thấy cách vẽ nhiều biểu đồ thanh bằng matplotlib, ở đây chúng ta đang vẽ nhiều biểu đồ thanh để hình dung số lượng nam và nữ trong mỗi nhóm.
    3. Nhập các thư viện bắt buộc như Numpy để thực hiện các tính toán số với các mảng và matplotlib để trực quan hóa dữ liệu.
    4. Dữ liệu để vẽ nhiều biểu đồ thanh được đưa vào danh sách.
    5. Hàm np.arange [] từ thư viện Numpy được sử dụng để tạo ra một loạt các giá trị. Chúng tôi đang tạo các giá trị trục x tùy thuộc vào số lượng nhóm trong ví dụ của chúng tôi.
    6. Vẽ đồ thị nhiều thanh bằng hàm plt.bar [].
    7. Để tránh chồng chéo các thanh trong mỗi nhóm, các thanh được dịch chuyển -0.2 đơn vị và +0.2 đơn vị từ trục X.
    8. Chiều rộng của các thanh của mỗi nhóm được lấy là 0,4 đơn vị.

    Code:

    Python3

    import =5

    import =7

    =8= [[1[2[3[2[5[22.

    [9= ['Group A'2[2'Group A'4____822

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    00=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    02

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    03=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    05

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    06=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    08

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    09__
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    11
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    0

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    13
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    06=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    16=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    18
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    0

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    13
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    21=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    23matplotlib.pyplot as plt 2

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    25matplotlib.pyplot as plt 4
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    27=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    29____10

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    13
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    06=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    16=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    18
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    0

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    13
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    21=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    41matplotlib.pyplot as plt 2

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    25matplotlib.pyplot as plt 4
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    27=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    29____10

    X 6

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    47matplotlib.pyplot as plt 2

    X 9

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    50matplotlib.pyplot as plt 2

    X 3

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    444____52

    =2

    =3

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    52matplotlib.pyplot as plt 4
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    54
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    55
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    56__

    Đầu ra:

    Approach:

    1. Ví dụ3: Điểm số của những người chơi khác nhau vào các ngày khác nhau
    2. Nhập các thư viện bắt buộc như Numpy để thực hiện các tính toán số với các mảng và matplotlib để trực quan hóa dữ liệu.
    3. Hàm np.arange [] từ thư viện Numpy được sử dụng để tạo ra một loạt các giá trị [ở đây, 3 giá trị].
    4. Vẽ đồ thị nhiều thanh bằng hàm plt.bar [] trong thư viện matplotlib. Trong ví dụ này, ngày được vẽ trên trục X và điểm số của người chơi trên trục y.
    5. Để tránh chồng chéo các thanh trong mỗi nhóm, các thanh được dịch chuyển 0,25 đơn vị từ thanh trước đó.
    6. Chiều rộng của các thanh của mỗi nhóm được lấy là 0,25 đơn vị với các màu khác nhau.
    7. Các nhãn trục X và Ticks X được vẽ theo yêu cầu trong trực quan hóa của chúng tôi.

    Code:

    Python3

    import =5

    import =7

    Cuối cùng, biểu đồ nhiều thanh cho điểm số của những người chơi khác nhau vào các ngày khác nhau được vẽ.

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    72=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    74

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    06=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    08

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    09__
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    11
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    0

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    13
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    06=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    16=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    18
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    0

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    25matplotlib.pyplot as plt 4
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    27=
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    29____10

    X 3

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    444____52

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    52matplotlib.pyplot as plt 4
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    54
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    55
    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    56__

    Đầu ra:

    X 3import34matplotlib.pyplot as plt 2

    X 6import37matplotlib.pyplot as plt 2

    X 9import40matplotlib.pyplot as plt 2

    import42matplotlib.pyplot as plt 4import44import45[2import47[2import49

    #
    import numpy as np
    import matplotlib.pyplot as plt
    
    # The data
    womenMeans = [25, 32, 34, 20, 25]
    menMeans = [20, 35, 30, 35, 27]
    indices = range[len[womenMeans]]
    names = ['Asian','European','North Amercian','African','Austrailian','Martian']
    # Calculate optimal width
    width = np.min[np.diff[indices]]/3.
    
    fig = plt.figure[]
    ax = fig.add_subplot[111]
    ax.bar[indices-width/2.,womenMeans,width,color='b',label='-Ymin']
    ax.bar[indices+width/2.,menMeans,width,color='r',label='Ymax']
    #tiks = ax.get_xticks[].tolist[]
    ax.axes.set_xticklabels[names]
    ax.set_xlabel['Test histogram']
    plt.show[]
    
    65

    import51import52[2import54[2import56import57

    =3

    Output:


    Làm thế nào để bạn vẽ hai biểu đồ trên cùng một biểu đồ trong Python?

    Gọi matplotlib.pyplot.plot [x, y] với x và y được đặt thành mảng các điểm dữ liệu để xây dựng một biểu đồ.Gọi hàm này nhiều lần trên cùng một hình tạo ra nhiều ô trong cùng một biểu đồ. pyplot. plot[x, y] with x and y set to arrays of data points to construct a plot. Calling this function multiple times on the same figure creates multiple plots in the same graph.

    Làm thế nào để bạn tạo một biểu đồ thanh đôi trên gấu trúc?

    Chúng ta có thể vẽ các thanh này với các cạnh chồng chéo hoặc trên cùng một trục.Các cách khác nhau để vẽ đồ thị thanh trong cùng một biểu đồ đang sử dụng matplotlib và gấu trúc được thảo luận dưới đây ...
    Nhập mô -đun ..
    Tạo hoặc tải dữ liệu ..
    Truyền dữ liệu để vẽ [].
    Đồ thị lô..

    Làm thế nào để bạn hiển thị hai biểu đồ trong Python?

    Sử dụng matplotlib ...
    x1 = [1, 2, 3].
    y1 = [4, 5, 6].
    x2 = [1, 3, 5].
    y2 = [6, 5, 4].
    Lô đất1 = plt.Hình 1].
    plt.Lô đất [x1, y1].
    Plot2 = plt.Hình 2].
    plt.Lô đất [x2, y2].

    Làm cách nào để tạo biểu đồ nhiều thanh?

    Để tạo biểu đồ nhiều thanh:..
    Vẽ trục ngang [x] và dọc [y] ..
    Cho biểu đồ một tiêu đề ..
    Dán nhãn trục x ngang ..
    Dán nhãn trục y dọc ..
    Nhìn vào phạm vi trong dữ liệu và quyết định cách các đơn vị trên trục dọc [y] nên được dán nhãn ..

    Bài Viết Liên Quan

    Chủ Đề