Ярлыки не отображаются на круговой диаграмме в приложении KivyMDPython

Программы на Python
Anonymous
Ярлыки не отображаются на круговой диаграмме в приложении KivyMD

Сообщение Anonymous »

В настоящее время я разрабатываю приложение KivyMD, которое включает в себя круговую диаграмму, используя Matplotlib. Однако метки не отображаются на круговой диаграмме, как ожидалось. Я использую функцию plt.pie() для создания круговой диаграммы, но метки для каждого сегмента не отображаются. Сегменты рисуются, но видимых меток или процентов нет. Что может быть причиной того, что метки не отображаются на круговой диаграмме?
Существуют ли какие-либо распространенные проблемы с рендерингом фигур Matplotlib в Kivy, о которых мне следует знать ?
Будем очень признательны за любую помощь или рекомендации!
ФАЙЛ KV
MDFloatLayout:
id: main_layout
size: root.width,root.height

MDBoxLayout:
id: plot_container

orientation: "vertical"

size_hint: None,None

width: 600

height: 400

padding: "5dp"

pos_hint: {"center_x": 0.6, "center_y":0.5}

MDBoxLayout:
id: menu_bar

orientation: "vertical"

size_hint: None,None

width: 120

height: root.height

pos_hint:{"center_x":0.07}

padding:"5dp"

spacing: "5dp"

canvas:
Color:
rgba: 163/255,216/255,239/255,1

Rectangle:
size:self.size

pos:self.pos

canvas.after:
Color:
rgba: 1,1,1,1

Rectangle:
source: "img/monitoring-test.png"

size:60,60

pos:(25,root.height - 65)

Widget:
size_hint: None,None

width: 115

height: 60

canvas:
Color:
rgba: 58/255,101/255,153/255,0

Rectangle:
size:self.size

pos:self.pos

MDIconButton:
icon: "img/bar-chart.png"

text: "Text1"

pos_hint: {"center_x":0.5}

icon_size: "50sp"

on_release: app.create_bar_plot()

MDLabel:
text: "Text1"

font_size: "16"

font_type: "Arial"

halign: "center"

bold: True

color: 0,0,0,1

Widget:
size_hint: None,None

width: 115

height: 50

canvas:
Color:
rgba: 58/255,101/255,153/255,0.2

Rectangle:
size:self.size

pos:self.pos

MDIconButton:
icon: "img/pie-chart.png"

text: "Text1"

pos_hint: {"center_x":0.5}

icon_size: "50sp"

on_release: app.create_pie_plot()

MDLabel:
text: "Text1"

font_size: "16"

font_type: "Arial"

halign: "center"

bold: True

color: 0,0,0,1

Widget:
size_hint: None,None

width: 115

height: 50

canvas:
Color:
rgba: 58/255,101/255,153/255,0.2

Rectangle:
size:self.size

pos:self.pos

MDIconButton:
icon: "img/bar-chart.png"

text: "Text1"

pos_hint: {"center_x":0.5}

icon_size: "50sp"

MDLabel:
text: "Text1"

font_size: "16"

font_type: "Arial"

halign: "center"

bold: True

color: 0,0,0,1

Widget:
size_hint: None,None

width: 115

height: 50

canvas:
Color:
rgba: 58/255,101/255,153/255,0.2

Rectangle:
size:self.size

pos:self.pos

PYTHON FILE

```
from kivymd.app import MDApp

from kivy.lang.builder import Builder

from kivy.animation import Animation

from kivy.uix.label import Label

from matplotlib import pyplot as plt

from kivy_garden.matplotlib import FigureCanvasKivy

class Dashboard(MDApp):

def build(self):
self.theme_cls.theme_style = "Light"
self.root = Builder.load_file("PoliFyp.kv")
self.create_bar_plot()
return self.root

def create_bar_plot(self):

plt.clf()

plot_container = self.root.ids.plot_container

plot_container.clear_widgets()

plot_container.width = 600

plot_container.height = 400

x = [11, 22, 33, 44, 55, 66, 77, 88, 99, 100]

y = [12, 6, 9, 15, 23, 67, 11, 90, 34, 91]

plt.bar(x, y,8,color='orange')

plt.ylabel("Y axis")

plt.xlabel("X axis")

plot_container.add_widget(FigureCanvasKivy(plt.gcf()))

def create_pie_plot(self):
plt.clf()

plot_container = self.root.ids.plot_container

plot_container.width = 500

plot_container.height = 900

sizes = [12, 6, 9]

labels = ["APPLE","BANANA","DATES"] # Example labels

plt.pie(sizes, labels=labels, autopct='%0.1f%%', startangle=140, textprops={'fontsize': 6})

plot_container.clear_widgets()

plot_container.add_widget(FigureCanvasKivy(plt.gcf()))

Dashboard().run()
```

Adjusted the fontsize and color in textprops.
Ensured that the sizes are not too small to display labels.
Verified that clear_widgets() is called before adding the new pie chart.
Checked that the background color of the plot is not obscuring the labels.
The pie chart segments render correctly, but the labels are missing


Подробнее здесь: https://stackoverflow.com/questions/790 ... pplication

Вернуться в «Python»