【问题标题】:Python 3d bar chart plotPython 3d 条形图
【发布时间】:2020-11-20 15:16:52
【问题描述】:

我是一个新的python,我想像这样在python中绘制一个3D条形图

非常感谢,

【问题讨论】:

    标签: python charts 3d bar-chart


    【解决方案1】:

    要在 python 中绘制此图表,您必须安装“numpy”和“matplotlib”库。然后绘制图表,您可以使用如下代码

    from mpl_toolkits.mplot3d import axes3d
    import matplotlib.pyplot as plt
    import numpy as np
    from matplotlib import style
    import os, sys
    from mpl_toolkits.mplot3d import Axes3D
    
    style.use('ggplot')
    
    fig = plt.figure()
    ax1 = fig.add_subplot(111, projection='3d')
    
    x3 = np.zeros(17)
     
    #Starting point coordinate for each company on the y-axis
    y3 = np.arange(1,18,1)
    z3 = np.zeros(17)
     
    #
    dx = np.ones(17)
    dy = np.ones(17)
    dz = [22,13, 0, 11,46, 0, 9,1, 0,24,4, 0, 17, 34,0, 17, 2]
    
    x = np.arange(2, 19, 3)
    
    colors = ['green','b','w',
              'green','b','w',
              'green','b','w',
              'green','b','w',
              'green','b','w',
              'green','b']
    
    rects1 = ax1.bar3d(x3, y3, z3, dx, dy, dz, color=colors, alpha=1)
     
    
    ax1.set_xticks([])
    
    ax1.set_yticks(x)
    
    
    x_ticks_labels = ['bus','car','bicycle','walking', 'train', 'motorcycle']
    proxy_1 = plt.Rectangle((0, 0), 1, 1, fc="green")
    proxy_2 = plt.Rectangle((0, 0), 1, 1, fc="b")
    ax1.set_yticklabels(x_ticks_labels, rotation='30')
    ax1.legend([proxy_1,proxy_2],['1960','2010'])
    
    ax1.view_init(elev=1, azim=1)
    plt.title("commuter ...")
    #Show the plot so you can see what it looks like before saving as a SVG. Save as a svg for better image quality on your website.
    plt.show()

    【讨论】:

    • 你是个天才,它对我有用。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2010-10-25
    • 2015-01-03
    • 2011-05-28
    • 2010-12-02
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多