How to plot this this graph?

后端 未结 2 751
误落风尘
误落风尘 2021-01-29 04:15

Hi Data Visulization Experts!

I\'m trying to plot this graph hand-drawn example here in python.

\"\"

<
相关标签:
2条回答
  • 2021-01-29 04:48

    Set your data up like this, then after you've selected the range for a bar chart, you'll need to swap the X and Y axis:

    0 讨论(0)
  • 2021-01-29 04:53

    Without the data I cannot assist in plotting it, but you can solve it via Python by following the examples at:

    https://matplotlib.org/gallery/units/bar_demo2.html?highlight=bar

    ^ You can perhaps have each bar chart on a separate subplot?

    If your input is multiple sets of data you can look into maybe a multiple dataset histogram at

    https://matplotlib.org/gallery/statistics/histogram_multihist.html?highlight=hist

    ^ If you want to have the first column of all categories next to each other, then the second bar, etc..

    Perhaps you would prefer just a standard histogram though:

    https://matplotlib.org/gallery/statistics/histogram_features.html?highlight=hist

    It really depends on what you are trying to emphasize from your data

    @EDIT

    Here is a Python program to plot your information! You can easily adjust the width (I commented out a way to set the width to cover the empty gaps, but its slightly off) and to plot a line I would use width = 0.01

    import matplotlib.pyplot as plt
    import numpy as np
    
    data = {0: [4, 8, 6],
            1: [2, 4, 3, 6],
            2: [3, 6],
            3: [10, 3, 8, 6, 10, 12]}
    
    fig, ax = plt.subplots(tight_layout=True)
    
    for key, values in data.items():
        ind = np.arange(key, key + 1, 1/len(data[key]))
        width = 0.1 # 1/len(data[key])
        ax.bar(ind + width/len(values), data[key], width, align='center', label="Category {}".format(key + 1))
    
    ax.xaxis.set_ticks([])
    ax.set_xticklabels(' ')
    ax.legend()
    ax.set_ylabel('Some vertical label')
    plt.title('My plot for Stack Overflow')
    plt.show()
    

    This outputs: Which I think is what you're looking for. This may not be a perfect solution, but I think it showcases the methodology used to make such plots :). If this solution solved your problem, I would appreciate if you could click the check mark by my post to accept it as the answer you were looking for!

    0 讨论(0)
提交回复
热议问题