简体   繁体   English

Chaco中的自动填充物?

[英]Automatic paddings in Chaco?

Is it possible to make chaco plot automatically show full output and not hiding the parts of ticks and labels? 是否可以使chaco图自动显示完整输出,而不隐藏刻度线和标签的部分? Eg this is the output of standard example: 例如,这是标准示例的输出:

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

在此处输入图片说明

As you see the part of tick labels are hidden.. the only thing I can do is to manually adjust left padding of the plot. 如您所见,刻度线标签的一部分被隐藏了。.我唯一能做的就是手动调整图的左填充。 But this becomes extremely incovinient when you plot different data and different scales or fonts with the plot in application. 但是,当您使用应用程序中的图来绘制不同的数据,不同的比例或字体时,这将变得极为不便。 Is it possible somehow to make padding automatically adjusted to include ALL related info? 是否有可能使填充自动调整为包括所有相关信息?

UPD.: I've found ensure_labels_bounded property for the axis, but seems it has no effect. UPD 。:我已经找到了该轴的sure_labels_bounded属性,但似乎没有任何作用。

Chaco does not support advanced layout features like these. Chaco不支持此类高级布局功能。 If you use Chaco, you should use it for its speed, not for nice graphs or features. 如果使用Chaco,则应将其用于速度,而不是用于精美的图形或功能。 That being said, here's a version as close as I could get. 话虽如此,这是我能得到的尽可能接近的版本。 It requires you to re-size the window with the mouse at least once for the padding correction to take place. 它要求您至少用鼠标重新调整窗口大小一次,以进行填充校正。 Maybe you can find a way to refresh the window without having to manually resize it, I didn't have any luck with that. 也许您可以找到一种无需手动调整窗口大小即可刷新窗口的方法,对此我没有任何运气。 Anyways hope that gets you on the right track. 无论如何,希望能使您走上正确的道路。

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