1
A
回答
1
編輯:此功能現已添加到Chaco 4.6,所以如果您使用的是此版本或更高版本,請使用以下類似的代碼。如果沒有看到下面的原始帖子。另請參閱文檔here和另一個示例here。
if __name__ == "__main__":
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'
#
import warnings
warnings.filterwarnings(action = "ignore", category = FutureWarning, module="chaco")
warnings.filterwarnings(action = "ignore", category = FutureWarning, module="traits")
#
from PySide import QtGui, QtCore
import numpy as np
from enable.api import Component, Container, Window
from chaco.api import *
import sys
#
class ChacoPlot(QtGui.QWidget):
def __init__(self, parent=None):
super(ChacoPlot, self).__init__(parent)
#
self.container = OverlayPlotContainer(padding=40)
#
self.enableWindow = Window(self, -1, component=self.container)
windowLayout = QtGui.QVBoxLayout(self)
windowLayout.addWidget(self.enableWindow.control)
#
self.xRange = DataRange1D()
self.yRange = DataRange1D()
#
self.xMapper = LinearMapper(range=self.xRange)
self.yMapper = LinearMapper(range=self.yRange)
#
self.plots = {}
# keep a list of plots added to the container
#
def setMinimumSize(self, width, height):
self.enableWindow.control.setMinimumSize(width, height)
#
def addLine(self, name, plotType):
xSource = ArrayDataSource([0])
ySource = ArrayDataSource([0])
#
self.xRange.add(xSource)
self.yRange.add(ySource)
#
index_mapper = self.xMapper
value_mapper = self.yMapper
#
# plotType is a class name
plot = plotType( index = xSource,
value = ySource,
index_mapper = index_mapper,
value_mapper = value_mapper,
visible = False
)
#
self.container.add(plot)
#
self.plots[name] = {'plot':plot, 'xSource':xSource, 'ySource':ySource}
#
def updateLine(self, name, xData, yData):
plot = self.plots[name]
#
if np.array(xData).size != 0:
plot['plot'].visible = True
else:
plot['plot'].visible = False
xData = [0]
yData = [0]
#
plot['xSource'].set_data(xData)
plot['ySource'].set_data(yData)
#
def addAxis(self, plotName, orientation):
plot = self.plots[plotName]['plot']
#
if orientation == 'top' or orientation == 'bottom':
mapper = self.xMapper
if orientation == 'left' or orientation == 'right':
mapper = self.yMapper
#
axis = PlotAxis(plot, orientation=orientation, mapper=mapper)
plot.overlays.append(axis)
#
return axis
#
def addMinorAxis(self, plotName, orientation):
plot = self.plots[plotName]['plot']
#
if orientation == 'top' or orientation == 'bottom':
mapper = self.xMapper
range = self.xRange
if orientation == 'left' or orientation == 'right':
mapper = self.yMapper
range = self.yRange
#
newAxis = MinorPlotAxis(plot, orientation=orientation, mapper=mapper)
plot.overlays.append(newAxis)
#
return axis
#
#
if __name__ == "__main__":
appQT = QtGui.QApplication.instance()
#
x1 = np.arange(300)/18.0
y1 = np.sin(x1)
x2 = np.arange(300)/18.0
y2 = 2.0*np.cos(x2)
#
plot = ChacoPlot()
plot.setMinimumSize(400,300)
#
plot.addLine('line1', LinePlot)
plot.addLine('line2', LinePlot)
plot.updateLine('line1', x1, y1)
plot.updateLine('line2', x2, y2)
#
plot.addAxis('line1', 'bottom')
plot.addAxis('line1', 'left')
plot.addMinorAxis('line1', 'bottom')
plot.addMinorAxis('line1', 'left')
#
plot.show()
appQT.exec_()
原文:查科沒有這個功能特別,但你可以通過增加一個額外PlotAxis
添加次要刻度線。您需要修改該軸的一些屬性:
tick_generator
- 該對象定義蜱tick_label_formatter
的位置 - 該函數返回刻度標籤字符串對於給定的刻度標記值tick_in
和tick_out
- 這些數字定義了滴答的大小(進出軸)
下面是一個示例。這是很多代碼,但它非常簡單。儘管使用Plot
輔助類來繪製地塊是很常見的,但我更喜歡手動創建地塊,因爲定製要容易得多。反正希望它有幫助。
if __name__ == "__main__":
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'
#
import warnings
warnings.filterwarnings(action = "ignore", category = FutureWarning, module="chaco")
warnings.filterwarnings(action = "ignore", category = FutureWarning, module="traits")
#
from PySide import QtGui, QtCore
import numpy as np
from enable.api import Component, Container, Window
from chaco.api import *
import sys
#
class ChacoPlot(QtGui.QWidget):
def __init__(self, parent=None):
super(ChacoPlot, self).__init__(parent)
#
self.container = OverlayPlotContainer(padding=40)
#
self.enableWindow = Window(self, -1, component=self.container)
windowLayout = QtGui.QVBoxLayout(self)
windowLayout.addWidget(self.enableWindow.control)
#
self.xRange = DataRange1D()
self.yRange = DataRange1D()
#
self.xMapper = LinearMapper(range=self.xRange)
self.yMapper = LinearMapper(range=self.yRange)
#
self.plots = {}
# keep a list of plots added to the container
#
def setMinimumSize(self, width, height):
self.enableWindow.control.setMinimumSize(width, height)
#
def addLine(self, name, plotType):
xSource = ArrayDataSource([0])
ySource = ArrayDataSource([0])
#
self.xRange.add(xSource)
self.yRange.add(ySource)
#
index_mapper = self.xMapper
value_mapper = self.yMapper
#
# plotType is a class name
plot = plotType( index = xSource,
value = ySource,
index_mapper = index_mapper,
value_mapper = value_mapper,
visible = False
)
#
self.container.add(plot)
#
self.plots[name] = {'plot':plot, 'xSource':xSource, 'ySource':ySource}
#
def updateLine(self, name, xData, yData):
plot = self.plots[name]
#
if np.array(xData).size != 0:
plot['plot'].visible = True
else:
plot['plot'].visible = False
xData = [0]
yData = [0]
#
plot['xSource'].set_data(xData)
plot['ySource'].set_data(yData)
#
def addAxis(self, plotName, orientation):
plot = self.plots[plotName]['plot']
#
if orientation == 'top' or orientation == 'bottom':
mapper = self.xMapper
if orientation == 'left' or orientation == 'right':
mapper = self.yMapper
#
axis = PlotAxis(plot, orientation=orientation, mapper=mapper)
plot.overlays.append(axis)
#
return axis
#
def addMinorAxis(self, plotName, orientation):
plot = self.plots[plotName]['plot']
#
if orientation == 'top' or orientation == 'bottom':
mapper = self.xMapper
range = self.xRange
if orientation == 'left' or orientation == 'right':
mapper = self.yMapper
range = self.yRange
#
newAxis = PlotAxis(plot, orientation=orientation, mapper=mapper)
plot.overlays.append(newAxis)
#
newAxis.tick_generator = MinorTickGenerator()
#
newAxis.tick_label_formatter = lambda x: ''
newAxis.tick_in = 2
newAxis.tick_out = 2
#
#
class MinorTickGenerator(AbstractTickGenerator):
def __init__(self):
super(MinorTickGenerator, self).__init__()
#
def get_ticks(self, data_low, data_high, bounds_low, bounds_high, interval, use_endpoints=False, scale='linear'):
interval = interval
#
if interval == 'auto':
interval = auto_interval(data_low, data_high)/5.0
#
return auto_ticks(data_low, data_high, bounds_low, bounds_high, interval, use_endpoints)
#
#
if __name__ == "__main__":
appQT = QtGui.QApplication.instance()
#
x1 = np.arange(300)/18.0
y1 = np.sin(x1)
x2 = np.arange(300)/18.0
y2 = 2.0*np.cos(x2)
#
plot = ChacoPlot()
plot.setMinimumSize(400,300)
#
plot.addLine('line1', LinePlot)
plot.addLine('line2', LinePlot)
plot.updateLine('line1', x1, y1)
plot.updateLine('line2', x2, y2)
#
plot.addAxis('line1', 'bottom')
plot.addAxis('line1', 'left')
plot.addMinorAxis('line1', 'bottom')
plot.addMinorAxis('line1', 'left')
#
plot.show()
appQT.exec_()
相關問題
- 1. python函數的小提琴劇情和劇情
- 2. MATLAB:劇情隨機信號
- 3. Python小提琴劇情
- 4. 小提琴劇情Matlab
- 5. python小提琴劇情
- 6. ggplot2(R)中未顯示的小勾號
- 7. 劇情中的R
- 8. 劇情中的R
- 9. 彙總值的小提琴劇情(geom_violin)
- 10. 突出顯示一條線上的單個劇情符號 - 核心劇情
- 11. 我的jQuery幻燈片中有一個小小的勾號?
- 12. 支線劇情,劇情無厘頭
- 13. Python:劇情在scipy劇情之上? (voronoi)
- 14. 核心 - 劇情:個性化劇情
- 15. ggplot2用劇情符號標註文字
- 16. Xamarin Oxyplot:如何隱藏YAxis小勾號?
- 17. Zedgraph - 最後一個小勾號消失
- 18. 劇情值
- 19. 與Android劇情
- 20. 互動劇情
- 21. 劇情值
- 22. 劇情時間
- 23. BeamDeflection劇情
- 24. ggplot2中小提琴劇情的中位數和四分位數
- 25. 如何在選中時更改劇情符號的顏色iPhone
- 26. 如何在gnuplot的ruby實現中指定劇情符號?
- 27. 3D情節劇情 - R
- 28. Highcharts - 劇情標籤後面的隱藏劇情線
- 29. 劇情時間序列(24小時)中的R
- 30. 劇情中的小提琴曲風格直方圖
很想看到,變成了查科源公關... –