Matplotlib 3D Bar chart: axis issue

前端 未结 2 1416
眼角桃花
眼角桃花 2021-02-06 17:20

I am having issue with getting data on x,y,z axis..below is my code. Is there any issue with the way i have defined range(dx,dy.dz) for different axis.

result=[         


        
2条回答
  •  爱一瞬间的悲伤
    2021-02-06 17:27

    As the error suggests, your result list has to contain integers, and not strings. You can convert it to integers with list comprehension:

    result = [[int(i) for i in sublist] for sublist in result]
    

    Or, better yet, you can use np.array:

    import numpy as np
    result = np.array(result, dtype=np.int)
    

    Update:

    As bar3d documentation (and example) suggest, ipos arrays should hold the positions of bars; di arrays should hold the distances between bars. Your xpos and ypos lists hold what is called the tick labels. So, you need to change these and then set tick labels of relevant axes to given xpos and ypos. According tho the example provided, you can do it in the following way:

    xpos, ypos = np.meshgrid(np.arange(5)+0.5, np.arange(7)+0.5)
    xpos = xpos.flatten()
    ypos = ypos.flatten()
    zpos = np.zeros(5*7)
    dx = np.ones_like(zpos)
    dy = dx.copy()
    dz = result.flatten()
    xticks=['','10/11/2013','10/12/2013','10/13/2013','10/14/2013','10/15/2013']
    yticks=['','A1','C1','G1','M1','M2','M3','P1']
    ax1.set_xticklabels(xticks)
    ax1.set_yticklabels(yticks)
    

提交回复
热议问题