简体   繁体   English

如何绘制此图?

[英]How to plot this this graph?

Hi Data Visulization Experts! 嗨,数据可视化专家!

I'm trying to plot this graph hand-drawn example here in python. 我正在尝试在python中绘制此图形手绘示例。

However, it seems it will be much trickier to plot as compared to normal plots. 但是,与正常绘图相比,绘图要困难得多。

It would be really nice if a visualisation expert can help in plotting this. 如果可视化专家可以帮助您对此进行绘制,那将是非常不错的。 In the hand-drawn figure I kept all the lines red, however, they can be in different colours. 在手绘图中,我将所有线条保留为红色,但是它们可以使用不同的颜色。

Thank you for your responses :) 谢谢您的反馈 :)

Without the data I cannot assist in plotting it, but you can solve it via Python by following the examples at: 没有数据,我无法协助绘制,但是您可以按照以下示例通过Python解决:

https://matplotlib.org/gallery/units/bar_demo2.html?highlight=bar 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 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 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! 这是一个Python程序,用于绘制您的信息! 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 您可以轻松地调整宽度(我注释掉了一种设置宽度以覆盖空白的方法,但略有偏离)并绘制一条线,我将使用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! 如果此解决方案解决了您的问题,希望您可以单击我的帖子旁边的复选标记以接受它作为您要的答案!

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: 像这样设置数据,然后在选择条形图的范围后,需要交换X和Y轴:

img1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM