填充直方图有问题吗?

2024-10-01 02:39:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我似乎无法用数据填充这个柱状图。设置格式,但不显示数据

x_val = [1.71, 1.72, 1.73, 1.74, 1.75, 1.76, 1.77, 1.78, 1.79, 1.8, 
         1.81, 1.82, 1.83, 1.84, 1.85, 1.86,
         1.87, 1.88, 1.89, 1.9, 1.91, 1.92]

y_val =  [62.91, 1675.13, 2720.45, 7090.28, 18777.94, 18795.57,   
          30726.06, 31396.96, 18351.63, 32014.1, 7791.73, 1594.0, 
          1471.25, 1539.42, 985.94, 402.44, 68.58, 18.17, 97.74, 43.61, 20.0, 6.0]

def generateChart():

    plt.hist(y_val, bins=22, align='left')
    plt.title('Distribution of Market Trades (£)')
    plt.xlabel('Prices')
    plt.ylabel('Sizes')
    plt.xlim(min(x_val), max(x_val))
    plt.ylim(0, max(y_val))
    plt.show()

generateChart()

Tags: of数据titledef格式pltvalleft