AxisItem correctly handles scaling with values that are not power of 10
Can remove items from legend
updated plotItem setLogMode to allow unspecified axes
This commit is contained in:
Luke Campagnola 2013-05-09 23:02:14 -04:00
parent 00e865f56c
commit 671e624f17
4 changed files with 55 additions and 8 deletions

View File

@ -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)

View File

@ -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

View File

@ -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:

View File

@ -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):
"""