Running the following complete minimal example (from cmap_image_plot.py) with arg t >= 20 shows the trick: the x axis tick interval (every 2 h) does not match the x grid tick interval (every 3 h):
#!/usr/bin/env python3
"""
Draws a colormapped image plot
- Left-drag pans the plot.
- Mousewheel up and down zooms the plot in and out.
- Pressing "z" brings up the Zoom Box, and you can click-drag a rectangular
region to zoom. If you use a sequence of zoom boxes, pressing alt-left-arrow
and alt-right-arrow moves you forwards and backwards through the "zoom
history".
"""
# Major library imports
from numpy import exp, linspace, meshgrid
from sys import argv
# Enthought library imports
from enable.api import Component, ComponentEditor
from traits.api import HasTraits, Instance
from traitsui.api import Item, Group, View
# Chaco imports
from chaco.api import ArrayPlotData, viridis, Plot
from chaco.tools.api import PanTool, ZoomTool
from chaco.scales.api import CalendarScaleSystem, ScaleSystem
from chaco.scales.time_scale import HMSScales, MDYScales
from chaco.scales_tick_generator import ScalesTickGenerator
# ===============================================================================
# # Create the Chaco plot.
# ===============================================================================
def _create_plot_component():
# Create a scalar field to colormap
t = int(argv[1])
xs = linspace(0, t*3600, 600) - 3600
ys = linspace(0, 5, 600)
x, y = meshgrid(xs, ys)
z = exp(-((x/xs.max()) ** 2 + y ** 2) / 100)
# Create a plot data object and give it this data
pd = ArrayPlotData()
pd.set_data("imagedata", z)
# Create the plot
plot = Plot(pd)
img_plot = plot.img_plot(
"imagedata",
xbounds=(xs.min(), xs.max()),
ybounds=(0, 5),
colormap=viridis
)[0]
xgrid, ygrid, xaxis, yaxis = plot.underlays
print([a.orientation for a in plot.underlays])
xgrid.tick_generator = ScalesTickGenerator(scale=CalendarScaleSystem(scales=HMSScales))
xgrid.visible = True
xaxis.tick_generator = ScalesTickGenerator(scale=CalendarScaleSystem(scales=HMSScales))
ygrid.visible = xgrid.visible
xgrid.line_color = ygrid.line_color = (0, 0, 0)
# Attach some tools to the plot
plot.tools.append(PanTool(plot))
zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False)
img_plot.overlays.append(zoom)
return plot
# ===============================================================================
# Attributes to use for the plot view.
size = (1200, 800)
title = "Basic Colormapped Image Plot"
# ===============================================================================
# # Demo class that is used by the demo.py application.
# ===============================================================================
class Demo(HasTraits):
plot = Instance(Component)
traits_view = View(
Group(
Item("plot", editor=ComponentEditor(size=size), show_label=False),
orientation="vertical",
),
resizable=True,
title=title,
)
def _plot_default(self):
return _create_plot_component()
demo = Demo()
if __name__ == "__main__":
demo.configure_traits()```
Any idea?
Running the following complete minimal example (from cmap_image_plot.py) with arg t >= 20 shows the trick: the x axis tick interval (every 2 h) does not match the x grid tick interval (every 3 h):