Numpy 在pylab中打印范围而不是单个数字

Numpy 在pylab中打印范围而不是单个数字,numpy,matplotlib,Numpy,Matplotlib,我试图让x轴有刻度线的范围,而不仅仅是单个数字。我从用户的列表中获取一个输入,并希望将该列表分成相等的部分。(a_list是用户输入列表) 从现在起,它就崩溃了 import pylab import numpy def bar_graph(a_list): '''bar graph of number-frequency, xaxis labeled with ranges''' y_values = a_list.split(',') # get ticks as

我试图让x轴有刻度线的范围,而不仅仅是单个数字。我从用户的列表中获取一个输入,并希望将该列表分成相等的部分。(
a_list
是用户输入列表)

从现在起,它就崩溃了

import pylab
import numpy

def bar_graph(a_list):
    '''bar graph of number-frequency, xaxis labeled with ranges'''
    y_values = a_list.split(',')
    # get ticks as ranges
    bar_width=2
    x_values = numpy.arange[(max-min)/10]-1
    xvalues_ticked = x_values+bar_width/2.0
    pylab.xticks(xvalues_ticked,a_list)
    # create the bar graph
    pylab.bar(x_values,y_values,width=bar_width,color='r')
    pylab.xlabel("Ranges")
    pylab.ylabel("Frequency")
    pylab.title("Frequency of Numbers")
    pylab.plot(x_values,value_list,color='b')
    pylab.grid(True)
    pylab.show()



#Create number list

a_list = [1,5,10,20,25,55,30,70,45,15]
bar_graph(a_list)

这是我对你想做什么的最好猜测:

import matplotlib.pyplot as plt
import numpy as np


def bar_graph(ax, a_list):
    '''bar graph of number-frequency, xaxis labeled with ranges'''
    if isinstance(a_list, str):
        a_list = [float(_) for _ in a_list.split(',')]

    y_values = a_list
    x_values = np.arange(len(y_values)) * 2
    # get ticks as ranges
    bar_width = 2


    # create the bar graph
    ax.bar(x_values, y_values, width=bar_width, color='r', align='center')
    ax.xaxis.set_ticks(x_values)
    ax.xaxis.set_ticklabels(['{}-{}'.format(x, x+bar_width) for x in x_values])
    ax.set_xlabel("Ranges")
    ax.set_ylabel("Frequency")
    ax.set_title("Frequency of Numbers")
    ax.plot(x_values, y_values, color='b')
    ax.grid(True)




a_list = [1,5,10,20,25,55,30,70,45,15]

fig, ax = plt.subplots()
bar_graph(ax, a_list)

我不明白你要什么。你能给我们一些关于这行代码的上下文吗?现在还不清楚你想做什么,这是无效的python。