【问题标题】:How to make stack of icons on a bar graph?如何在条形图上制作一堆图标?
【发布时间】:2020-01-12 08:03:08
【问题描述】:

我在尝试用 Python 制作条形图时遇到了麻烦,但“条”是图像堆栈而不是矩形。我正在使用 matplotlib,但找不到与此类似的功能。有没有办法做到这一点?甚至使用另一个库?

这是我想要生成的示例:

【问题讨论】:

标签: python matplotlib plot graph


【解决方案1】:

根据post,这就是我最终的做法:

fruits = {"Green": ["Grapes"],
          "Orange": ["Apricot", "Orange"],
          "Red": ["Strawberry", "Apple", "Cherry"],
          "Yellow": ["Banana"]}

for i, color in enumerate(fruits):
    for j, fruit_name in enumerate(fruits[color]):
        image = mpimg.imread(fruit_name)
        plt.imshow(image, extent=[i - 0.5, i + 0.5, j, j + 1])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-24
    • 2020-09-28
    • 1970-01-01
    • 2023-04-01
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 2014-12-28
    相关资源
    最近更新 更多