gpt4 book ai didi

kivy - 增加 Kivy 中 MeshLinePlot 的线宽?

转载 作者:行者123 更新时间:2023-12-05 07:39:13 27 4
gpt4 key购买 nike

有谁知道如何在 Kivy 中增加 MeshLinePlot 的线宽?

谢谢

更新

我从@Ikolim 那里得到了关于修改 kivy.graph 中的 LinePLot 函数的答案

class LinePlot(Plot):
'''LinePlot draws using a standard Line object.
'''

'''Args:
line_width (float) - the width of the graph line
'''

def __init__(self, line_width=1, **kwargs):
self._line_width = line_width # instead of kwargs.get('line_width', 1)
super(LinePlot, self).__init__(**kwargs)

最佳答案

基于 Kivy garden.graph 的方法 __init__ https://github.com/kivy-garden/garden.graph/blob/master/init.py , MeshLinePlot 目前不支持线宽。但是 LinePlot 确实支持线宽。

片段

    self.plot = LinePlot(line_width=4, color=[1, 0, 0, 1])

例子

主.py
import kivy
kivy.require("1.10.0")

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout

from kivy.garden.graph import Graph, MeshLinePlot, MeshStemPlot, LinePlot, SmoothLinePlot, ContourPlot
import matplotlib.pyplot as plt
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvas
from kivy.utils import get_color_from_hex as rgb
from numpy import sin


kv = """
<GraphCustom>:

<Test>:
orientation: 'vertical'
GraphCustom:
size: self.parent.size
pos: self.parent.pos
"""

Builder.load_string(kv)


class GraphCustom(Graph):
def __init__(self, **kwargs):
super(GraphCustom, self).__init__(**kwargs)
self.label_options = {'color': rgb('#FF0000'), 'bold': True}
self.background_color = rgb('f8f8f2')
self.tick_color = rgb('808080')
self.border_color = rgb('808080')
self.xlabel = 'X'
self.ylabel = 'Y'
self.x_ticks_minor = 5
self.x_ticks_major = 25
self.y_ticks_major = 1
self.y_grid_label = True
self.x_grid_label = True
self.padding = 5
self.x_grid = True
self.y_grid = True
self.xmin = -0
self.xmax = 100
self.ymin = -1
self.ymax = 1
self.stop = False

self.plot = LinePlot(line_width=4, color=[1, 0, 0, 1])
self.plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
self.add_plot(self.plot)


class Test(BoxLayout):
def __init__(self, *args, **kwargs):
super(Test, self).__init__(*args, **kwargs)
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
wid = FigureCanvas(fig1)
self.add_widget(wid)


class TestApp(App):
title = "Kivy Garden Graph - LinePlot Demo"

def build(self):
return Test()


if __name__ == '__main__':
TestApp().run()

输出

enter image description here enter image description here

关于kivy - 增加 Kivy 中 MeshLinePlot 的线宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47198739/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com