Как показывать галочки в логе Kivy Graph? - PullRequest
0 голосов
/ 02 ноября 2019

Если я строю линейный график, используя Kivy Garden Graph, я могу показывать метки и метки x и y. Я не могу найти способ пометить ось, если она масштабирована по логу.

У меня есть MWE, который отображает функцию на графике y-linear и y-log, но метки оси y не будутотображаются на графике журнала.

from kivy.lang import Builder
from kivy.garden.graph import Graph, MeshLinePlot
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.recycleview import RecycleView
from kivy.properties import BooleanProperty
import math
Builder.load_string("""
<MyLayout>:
    orientation: 'vertical'
    spacing: 10
    LinearGraph:
    LogGraph:
""")

class MyLayout(BoxLayout):
    pass

class LinearGraph(Graph):
    def __init__(self,**kwargs):
        super(LinearGraph, self).__init__(**kwargs)
        self.xlabel='X'
        self.ylabel='Y'
        self.x_ticks_major=25
        self.x_ticks_minor=5
        self.x_grid_label=True
        self.y_ticks_major=1
        self.y_grid_label=True
        self.xmin=0
        self.xmax=100
        self.ymin=0.1
        self.ymax=10
        self.ylog=False
        self.x_grid=True
        self.y_grid=True
        self.plot=MeshLinePlot(color=[1,1,1,1])
        self.add_plot(self.plot)
        self.plot.points=[(x, math.sin(x / 10.)+2) for x in range(0, 101)]

class LogGraph(Graph):
    def __init__(self,**kwargs):
        super(LogGraph, self).__init__(**kwargs)
        self.xlabel='X'
        self.ylabel='Y'
        self.x_ticks_major=25
        self.x_ticks_minor=5
        self.x_grid_label=True
        self.y_ticks_major=1
        self.y_grid_label=True
        self.xmin=0
        self.xmax=100
        self.ymin=0.1
        self.ymax=10
        self.ylog=True
        self.x_grid=True
        self.y_grid=True
        self.plot=MeshLinePlot(color=[1,1,1,1])
        self.add_plot(self.plot)
        self.plot.points=[(x, math.sin(x / 10.)+2) for x in range(0, 101)]


class MainscreenApp(App):
    def build(self):
        return MyLayout()

if __name__=="__main__":
    MainscreenApp().run()

Я бы не ожидал, что тики исчезнут - есть ли проблема с использованием класса Graph?

1 Ответ

1 голос
/ 03 ноября 2019

Трудно найти документы, но внутри кода для kivy.garden.graph написано:

x_ticks_major = BoundedNumericProperty(0, min=0)
'''Distance between major tick marks on the x-axis.

Determines the distance between the major tick marks. Major tick marks
start from min and re-occur at every ticks_major until :data:`xmax`.
If :data:`xmax` doesn't overlap with a integer multiple of ticks_major,
no tick will occur at :data:`xmax`. Zero indicates no tick marks.

If :data:`xlog` is true, then this indicates the distance between ticks
in multiples of current decade. E.g. if :data:`xmin` is 0.1 and
ticks_major is 0.1, it means there will be a tick at every 10th of the
decade, i.e. 0.1 ... 0.9, 1, 2... If it is 0.3, the ticks will occur at
0.1, 0.3, 0.6, 0.9, 2, 5, 8, 10. You'll notice that it went from 8 to 10
instead of to 20, that's so that we can say 0.5 and have ticks at every
half decade, e.g. 0.1, 0.5, 1, 5, 10, 50... Similarly, if ticks_major is
1.5, there will be ticks at 0.1, 5, 100, 5,000... Also notice, that there's
always a major tick at the start. Finally, if e.g. :data:`xmin` is 0.6
and this 0.5 there will be ticks at 0.6, 1, 5...

А в документах для y_ticks_major написано:

См .: данные: x_ticks_major

Обратите внимание, что если это log масштаб, то значение для y_ticks_major не является интуитивным.

Вы можетеполучить отметки, метки и сетку на оси Y, используя следующие значения (например):

    self.y_grid_label=True
    self.ymin=0.1
    self.ymax=10
    self.ylog=True
    self.y_grid=True 
    self.y_ticks_major=0.25
    self.y_ticks_minor=5
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...