Contour plot does not work with logarithmic scale
- Dominant language
- Python
- Stars
- 305
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
The `contour_plot` method is not correctly scaled in a logarithmic plot. Here is a modified example that exhibits this bug:
``` python
#!/usr/bin/env python
"""
This example illustrates a problem with the contour_plot with a logarithmic
axis scaling. This file is a modification of contour_plot.py
Draws a contour polygon plot with a contour line plot on top
- 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 cosh, exp, linspace, meshgrid, pi, tanh, sin
# 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, jet, Plot
from chaco.tools.api import PanTool, ZoomTool
#===============================================================================
# # Create the Chaco plot.
#===============================================================================
def _create_plot_component():
# Create a scalar field to contour
xs = linspace(1, 100, 600)
ys = linspace(0, 10, 300)
x, y = meshgrid(xs,ys)
z = x*y
# Create a plot data obect and give it this data
pd = ArrayPlotData()
pd.set_data("imagedata", z)
plot = Plot(pd, default_origin="top left")
# Add a line plot with a log scale
pd.set_data("xline", xs)
pd.set_data("yline", ys*100)
plot.plot(("xline", "yline"), color="blue", index_scale="log")
# Create a contour line plot for the data, too
cplot = plot.contour_plot("imagedata", type="line")
# Tweak some of the plot properties
plot.title = "Drag and drop the plot to see how the black contour plot gets rescaled (bug).\n It should behave like the blue line (reference)."
plot.bg_color = "white"
plot.fill_padding = True
# Attach some tools to the plot
plot.tools.append(PanTool(plot))
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
plot.overlays.append(zoom)
return plot
#===============================================================================
# Attributes to use for the plot view.
size = (800, 600)
title = "Contour plot logarithmic scaling bug"
#===============================================================================
# # 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()
#--EOF---
```


I have also tried the `index_scale="log"` keyword argument, but it does not change anything.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.