diff --git a/chaco/axis.py b/chaco/axis.py index 17763ad08..f9699a1c2 100644 --- a/chaco/axis.py +++ b/chaco/axis.py @@ -52,6 +52,9 @@ class PlotAxis(AbstractOverlay): # The color of the title. title_color = ColorTrait("black") + # The angle of the title, in degrees, from horizontal line + title_angle = Float(0.) + # The thickness (in pixels) of each tick. tick_weight = Float(1.0) @@ -535,7 +538,6 @@ def _calculate_geometry(self): self._minor_axis_size = self.bounds[1] self._major_axis = array([1., 0.]) self._title_orientation = array([0.,1.]) - self.title_angle = 0.0 if self.orientation == 'top': self._origin_point = array(self.position) self._inside_vector = array([0.,-1.]) @@ -553,11 +555,9 @@ def _calculate_geometry(self): if self.orientation == 'left': self._origin_point = array(self.position) + array([self.bounds[0], 0.]) self._inside_vector = array([1., 0.]) - self.title_angle = 90.0 else: #self.orientation == 'right' self._origin_point = array(self.position) self._inside_vector = array([-1., 0.]) - self.title_angle = 270.0 if "top" in origin: screenlow, screenhigh = screenhigh, screenlow @@ -584,7 +584,6 @@ def _calculate_geometry_overlay(self, overlay_component=None): self._minor_axis_size = overlay_component.bounds[1] self._major_axis = array([1., 0.]) self._title_orientation = array([0.,1.]) - self.title_angle = 0.0 if self.orientation == 'top': self._origin_point = array([overlay_component.x, overlay_component.y2]) self._inside_vector = array([0.0, -1.0]) @@ -602,11 +601,9 @@ def _calculate_geometry_overlay(self, overlay_component=None): if self.orientation == 'left': self._origin_point = array([overlay_component.x, overlay_component.y]) self._inside_vector = array([1.0, 0.0]) - self.title_angle = 90.0 else: self._origin_point = array([overlay_component.x2, overlay_component.y]) self._inside_vector = array([-1.0, 0.0]) - self.title_angle = 270.0 if "top" in component_origin: screenlow, screenhigh = screenhigh, screenlow @@ -728,6 +725,7 @@ def _anytrait_changed(self, name, old, new): 'title_font', 'title_spacing', 'title_color', + 'title_angle', 'tick_weight', 'tick_color', 'tick_label_font', @@ -756,6 +754,18 @@ def _anytrait_changed(self, name, old, new): if name in invalidate_traits: self._invalidate() + # ------------------------------------------------------------------------ + # Initialization-related methods + # ------------------------------------------------------------------------ + + def _title_angle_default(self): + if self.orientation == 'left': + return 90.0 + if self.orientation == 'right': + return 270.0 + # Then self.orientation in {'top', 'bottom'} + return 0.0 + #------------------------------------------------------------------------ # Persistence-related methods #------------------------------------------------------------------------ @@ -795,6 +805,7 @@ def __setstate__(self, state): self._cache_valid = False return + class MinorPlotAxis(PlotAxis): """ The MinorPlotAxis is a PlotAxis which draws ticks with a smaller interval, diff --git a/docs/source/user_manual/basic_elements/overlays.rst b/docs/source/user_manual/basic_elements/overlays.rst index 7343a1572..fa5a24e88 100644 --- a/docs/source/user_manual/basic_elements/overlays.rst +++ b/docs/source/user_manual/basic_elements/overlays.rst @@ -88,6 +88,7 @@ These attributes control the appearance of the axis: :attr:`~chaco.axis.PlotAxis.title_font`, :attr:`~chaco.axis.PlotAxis.title_color`, :attr:`~chaco.axis.PlotAxis.title_spacing` +:attr:`~chaco.axis.PlotAxis.title_angle` Define the axis label. :attr:`title` is a string or unicode object that is rendered using the given font and color. :attr:`title_font` is @@ -95,7 +96,9 @@ These attributes control the appearance of the axis: 'swiss family Arial' or 'default 12'; see :class:`~kiva.kiva_font_trait.TraitKivaFont` for details). Finally, :attr:`title_spacing` is the space between the axis line and the - title (either the number of pixels or 'auto', default). + title (either the number of pixels or 'auto', default) and + :attr:`title_angle` can be overridden to change the rotation angle (in deg, + wrt horizontal). :attr:`~chaco.axis.PlotAxis.tick_weight`, diff --git a/examples/demo/basic/line_plot1.py b/examples/demo/basic/line_plot1.py index 0a673144c..14b1075cc 100644 --- a/examples/demo/basic/line_plot1.py +++ b/examples/demo/basic/line_plot1.py @@ -34,10 +34,11 @@ def _create_plot_component(): pd.set_data("y" + str(i), jn(i,x)) # Create some line plots of some of the data - plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True) + plot1 = Plot(pd, title="Line Plot", padding=60, border_visible=True) plot1.legend.visible = True plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red") plot1.plot(("index", "y3"), name="j_3", color="blue") + plot1.value_axis.title = "J0, J1, J2, J3" # Attach some tools to the plot plot1.tools.append(PanTool(plot1)) @@ -46,10 +47,15 @@ def _create_plot_component(): # Create a second scatter plot of one of the datasets, linking its # range to the first plot - plot2 = Plot(pd, range2d=plot1.range2d, title="Scatter plot", padding=50, + plot2 = Plot(pd, range2d=plot1.range2d, title="Scatter plot", padding=60, border_visible=True) plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle") + # Configure the vertical axis: + plot2.value_axis.title = "J3" + plot2.value_axis.orientation = "right" + plot2.value_axis.title_angle = 0.0 # instead of default 270 deg + # Create a container and add our plots container = HPlotContainer() container.add(plot1)