简体   繁体   中英

Python Array with percentage bar

I would like to code in Python the following Image. I know mostly matplotlib but I'm open to use new package if necessary. Does anyone knows how to do something like this in Python? For me it looks like something I've never seen before to be honest.

Thank you for your help!

图片

Pyqt5 can provide you this:

import random
import sys
import time

from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QVBoxLayout

class Actions(QDialog):
    def __init__(self):
        super().__init__()
        self.initUI()
        
    def initUI(self):
        layout = QVBoxLayout(self)
        maxi = max(list_.values())
        for el in list_:
            bar = QProgressBar(self)
            bar.setRange(0, maxi)
            bar.setFormat(f"{el}: {list_[el]}mg (%p%)")
            bar.setValue(list_[el])
            layout.addWidget(bar)
        self.show()
  

if __name__ == "__main__":
    list_ = {
        "Vitamin A": 902,
        "Vitamin B1": 350,
        "Vitamin B2": 420,
        "Vitamin B3": 15.83,
        "Vitamin B5": 2.94,
    }
    app = QApplication(sys.argv)
    window = Actions()
    sys.exit(app.exec_())

Indeed you need to add theme, colors and other thing to have good render.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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