From 671e624f177f12f43da0971098b53c7f48bb6592 Mon Sep 17 00:00:00 2001
From: Luke Campagnola <luke.campagnola@gmail.com>
Date: Thu, 9 May 2013 23:02:14 -0400
Subject: [PATCH] Fixes: AxisItem correctly handles scaling with values that
 are not power of 10 Can remove items from legend updated plotItem setLogMode
 to allow unspecified axes

---
 examples/__main__.py                         |  1 +
 pyqtgraph/graphicsItems/AxisItem.py          | 20 +++++++++++--
 pyqtgraph/graphicsItems/LegendItem.py        | 30 ++++++++++++++++++++
 pyqtgraph/graphicsItems/PlotItem/PlotItem.py | 12 ++++----
 4 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/examples/__main__.py b/examples/__main__.py
index e7b89716..2ecc810d 100644
--- a/examples/__main__.py
+++ b/examples/__main__.py
@@ -3,6 +3,7 @@ import sys, os, subprocess, time
 try:
     from . import initExample
 except ValueError:
+    #__package__ = os.path.split(os.path.dirname(__file__))[-1]
     sys.excepthook(*sys.exc_info())
     print("examples/ can not be executed as a script; please run 'python -m examples' instead.")
     sys.exit(1)
diff --git a/pyqtgraph/graphicsItems/AxisItem.py b/pyqtgraph/graphicsItems/AxisItem.py
index d8c49390..846f48ac 100644
--- a/pyqtgraph/graphicsItems/AxisItem.py
+++ b/pyqtgraph/graphicsItems/AxisItem.py
@@ -281,7 +281,7 @@ class AxisItem(GraphicsWidget):
     def setScale(self, scale=None):
         """
         Set the value scaling for this axis. Values on the axis are multiplied
-        by this scale factor before being displayed as text. By default,
+        by this scale factor before being displayed as text. By default (scale=None),
         this scaling value is automatically determined based on the visible range
         and the axis units are updated to reflect the chosen scale factor.
         
@@ -301,6 +301,7 @@ class AxisItem(GraphicsWidget):
                 self.setLabel(unitPrefix=prefix)
             else:
                 scale = 1.0
+            self.autoScale = True
         else:
             self.setLabel(unitPrefix='')
             self.autoScale = False
@@ -499,6 +500,10 @@ class AxisItem(GraphicsWidget):
         """
         minVal, maxVal = sorted((minVal, maxVal))
         
+
+        minVal *= self.scale  
+        maxVal *= self.scale
+        #size *= self.scale
             
         ticks = []
         tickLevels = self.tickSpacing(minVal, maxVal, size)
@@ -511,16 +516,25 @@ class AxisItem(GraphicsWidget):
             
             ## determine number of ticks
             num = int((maxVal-start) / spacing) + 1
-            values = np.arange(num) * spacing + start
+            values = (np.arange(num) * spacing + start) / self.scale
             ## remove any ticks that were present in higher levels
             ## we assume here that if the difference between a tick value and a previously seen tick value
             ## is less than spacing/100, then they are 'equal' and we can ignore the new tick.
             values = list(filter(lambda x: all(np.abs(allValues-x) > spacing*0.01), values) )
             allValues = np.concatenate([allValues, values])
-            ticks.append((spacing, values))
+            ticks.append((spacing/self.scale, values))
             
         if self.logMode:
             return self.logTickValues(minVal, maxVal, size, ticks)
+        
+        
+        #nticks = []
+        #for t in ticks:
+            #nvals = []
+            #for v in t[1]:
+                #nvals.append(v/self.scale)
+            #nticks.append((t[0]/self.scale,nvals))
+        #ticks = nticks
             
         return ticks
     
diff --git a/pyqtgraph/graphicsItems/LegendItem.py b/pyqtgraph/graphicsItems/LegendItem.py
index c41feb95..3f4d5fa1 100644
--- a/pyqtgraph/graphicsItems/LegendItem.py
+++ b/pyqtgraph/graphicsItems/LegendItem.py
@@ -73,6 +73,36 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
         self.layout.addItem(sample, row, 0)
         self.layout.addItem(label, row, 1)
         self.updateSize()
+    
+    #
+    #
+    # Ulrich
+    def removeItem(self, name):
+        """
+        Removes one item from the legend. 
+
+        =========== ========================================================
+        Arguments
+        title       The title displayed for this item.
+        =========== ========================================================
+        """
+        # cycle for a match
+        for sample, label in self.items:
+            print label.text, name
+            if label.text == name:  # hit
+                self.items.remove( (sample, label) )    # remove from itemlist
+                self.layout.removeItem(sample)          # remove from layout
+                sample.close()                          # remove from drawing
+                self.layout.removeItem(label)
+                label.close()
+                self.updateSize()                       # redraq box
+
+    # hcirlU
+    #
+    #
+
+
+
         
     def updateSize(self):
         if self.size is not None:
diff --git a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
index c226b9c4..52a1429b 100644
--- a/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
+++ b/pyqtgraph/graphicsItems/PlotItem/PlotItem.py
@@ -295,19 +295,21 @@ class PlotItem(GraphicsWidget):
     
     
     
-    def setLogMode(self, x, y):
+    def setLogMode(self, x=None, y=None):
         """
-        Set log scaling for x and y axes.
+        Set log scaling for x and/or y axes.
         This informs PlotDataItems to transform logarithmically and switches
         the axes to use log ticking. 
         
         Note that *no other items* in the scene will be affected by
-        this; there is no generic way to redisplay a GraphicsItem
+        this; there is (currently) no generic way to redisplay a GraphicsItem
         with log coordinates.
         
         """
-        self.ctrl.logXCheck.setChecked(x)
-        self.ctrl.logYCheck.setChecked(y)
+        if x is not None:
+            self.ctrl.logXCheck.setChecked(x)
+        if y is not None:
+            self.ctrl.logYCheck.setChecked(y)
         
     def showGrid(self, x=None, y=None, alpha=None):
         """
-- 
GitLab