1

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 .:軸の ensure_labels_bounded プロパティを見つけましたが、効果がないようです。

4

1 に答える 1

1

Chaco は、このような高度なレイアウト機能をサポートしていません。Chaco を使用する場合は、優れたグラフや機能のためではなく、速度のために使用する必要があります。そうは言っても、ここに私が得ることができる限り近いバージョンがあります. パディングの修正を行うには、少なくとも 1 回はマウスでウィンドウのサイズを変更する必要があります。手動でサイズを変更せずにウィンドウを更新する方法を見つけることができるかもしれませんが、それはうまくいきませんでした。とにかく、それがあなたを正しい軌道に乗せることを願っています。

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

ここに画像の説明を入力

于 2016-01-15T07:25:45.263 に答える