增加Kivy中MeshLinePlot的线宽?

时间:2017-11-09 09:54:39

标签: kivy

有人知道如何在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)

1 个答案:

答案 0 :(得分:0)

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

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

实施例

main.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