簡體   English   中英

Chaco中的自動填充物?

[英]Automatic paddings in Chaco?

是否可以使chaco圖自動顯示完整輸出,而不隱藏刻度線和標簽的部分? 例如,這是標准示例的輸出:

from chaco.api import ArrayPlotData, Plot
from enable.component_editor import ComponentEditor

from traits.api import HasTraits, Instance
from traitsui.api import View, Item


class MyPlot(HasTraits):
    plot = Instance(Plot)
    traits_view = View(Item('plot', editor = ComponentEditor(), show_label = False),
                   width = 500, height = 500, resizable = True)

def __init__(self, x, y, *args, **kw):
    super(MyPlot, self).__init__(*args, **kw)
    plotdata = ArrayPlotData(x=x,y=y)
    plot = Plot(plotdata)
    plot.plot(("x","y"), type = "line", color = "blue")
    self.plot = plot


import numpy as np
x = np.linspace(-300,300,10000)
y = np.sin(x)*x**3
lineplot = MyPlot(x,y)
lineplot.configure_traits()

在此處輸入圖片說明

如您所見,刻度線標簽的一部分被隱藏了。.我唯一能做的就是手動調整圖的左填充。 但是,當您使用應用程序中的圖來繪制不同的數據,不同的比例或字體時,這將變得極為不便。 是否有可能使填充自動調整為包括所有相關信息?

UPD 。:我已經找到了該軸的sure_labels_bounded屬性,但似乎沒有任何作用。

Chaco不支持此類高級布局功能。 如果使用Chaco,則應將其用於速度,而不是用於精美的圖形或功能。 話雖如此,這是我能得到的盡可能接近的版本。 它要求您至少用鼠標重新調整窗口大小一次,以進行填充校正。 也許您可以找到一種無需手動調整窗口大小即可刷新窗口的方法,對此我沒有任何運氣。 無論如何,希望能使您走上正確的道路。

from chaco.api import ArrayPlotData, Plot
from enable.component_editor import ComponentEditor

from traits.api import HasTraits, Instance
from traitsui.api import View, Item

class MyPlot(HasTraits):
    plot = Instance(Plot)
    traits_view = View(Item('plot', editor = ComponentEditor(), show_label = False),
                   width = 500, height = 500, resizable = True)

    def __init__(self, x, y, *args, **kw):
        super(MyPlot, self).__init__(*args, **kw)
        plotdata = ArrayPlotData(x=x,y=y)
        plot = Plot(plotdata, padding=25)
        plot.plot(("x","y"), type = "line", color = "blue", name='abc')
        self.plot = plot
        # watch for changes to the bounding boxes of the tick labels
        self.plot.underlays[2].on_trait_change(self._update_size, '_tick_label_bounding_boxes')
        self.plot.underlays[3].on_trait_change(self._update_size, '_tick_label_bounding_boxes')
    def _update_size(self):
        if len(self.plot.underlays[2]._tick_label_bounding_boxes) > 0:
            self.plot.padding_bottom = int(np.amax(np.array(self.plot.underlays[2]._tick_label_bounding_boxes),0)[1]+8+4)
        if len(self.plot.underlays[3]._tick_label_bounding_boxes) > 0:
            self.plot.padding_left = int(np.amax(np.array(self.plot.underlays[3]._tick_label_bounding_boxes),0)[0]+8+4)

import numpy as np
x = np.linspace(-300,300,10000)
y = np.sin(x)*x**3
lineplot = MyPlot(x,y)
lineplot.configure_traits()

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM