Kaynağa Gözat

added graph axis labels

subDesTagesMitExtraKaese 3 yıl önce
ebeveyn
işleme
94a864b40a
1 değiştirilmiş dosya ile 5 ekleme ve 2 silme
  1. 5 2
      raspberry-pi/gui/graph.py

+ 5 - 2
raspberry-pi/gui/graph.py

@@ -39,6 +39,9 @@ class Graph(tk.Canvas):
     begin = math.floor(self.scale[0] / step) * step
     end   = math.ceil(self.scale[1] / step) * step
     halfStep = int(step / 2)
+    # label x and y axis
+    draw.text(self.pointToCoord(((end+begin)/2+25, -30)), "x in mm", font=self.font, align='center')
+    draw.text(self.pointToCoord((-45, (end+begin)/2+25)), "y in mm", font=self.font, align='left')
     for p in range(begin, end, halfStep):
       tickPosX = self.pointToCoord((p, 0))
       tickPosY = self.pointToCoord((0, p))
@@ -52,9 +55,9 @@ class Graph(tk.Canvas):
       draw.line([(tickPosX[0], tickPosX[1]+self.lineWidth*3), (tickPosX[0], tickPosX[1]-self.lineWidth*3)], (60,127,100), int(self.lineWidth/2))
       draw.line([(tickPosY[0]+self.lineWidth*3, tickPosY[1]), (tickPosY[0]-self.lineWidth*3, tickPosY[1])], (60,127,100), int(self.lineWidth/2))
       # draw tick labels
-      draw.text((tickPosX[0]+3, tickPosX[1]+self.lineWidth*4), str(p) + " mm", font=self.font)
+      draw.text((tickPosX[0]+3, tickPosX[1]+self.lineWidth*1), str(p), font=self.font)
       if p != 0:
-        draw.text((tickPosY[0]-self.lineWidth*4-35, tickPosY[1]), str(p) + " mm", font=self.font)
+        draw.text((tickPosY[0]+self.lineWidth*2, tickPosY[1]), str(p), font=self.font, align='right')
 
   def on_resize(self,event):
     self.width = max(100, event.width-4)