We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Replace mutable default argument in plot_factory create_*_plot functions
Replace the use of mutable default `data` argument to the `create_*_plot` functions in the `plot_factory` module.

https://github.com/enthought/chaco/blob/ef7227706642f7d26042717ad9b60648d7572068/chaco/plot_factory.py#L43
https://github.com/enthought/chaco/blob/ef7227706642f7d26042717ad9b60648d7572068/chaco/plot_factory.py#L91
https://github.com/enthought/chaco/blob/ef7227706642f7d26042717ad9b60648d7572068/chaco/plot_factory.py#L136



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chaco/plot_factory.py`
Content:
```
1 """
2 Contains convenience functions to create ready-made PlotRenderer instances of
3 various types.
4 """
5 
6 from numpy import array, ndarray, transpose, cos, sin
7 
8 # Local relative imports
9 from .abstract_data_source import AbstractDataSource
10 from .array_data_source import ArrayDataSource
11 from .axis import PlotAxis
12 from .barplot import BarPlot
13 from .data_range_1d import DataRange1D
14 from .grid import PlotGrid
15 from .linear_mapper import LinearMapper
16 from .scatterplot import ScatterPlot
17 from .polar_mapper import PolarMapper
18 from .lineplot import LinePlot
19 from .polar_line_renderer import PolarLineRenderer
20 
21 
22 def _create_data_sources(data, index_sort="none"):
23     """
24     Returns datasources for index and value based on the inputs.  Assumes that
25     the index data is unsorted unless otherwise specified.
26     """
27     if (type(data) == ndarray) or (len(data) == 2):
28         index, value = data
29         if type(index) in (list, tuple, ndarray):
30             index = ArrayDataSource(array(index), sort_order=index_sort)
31         elif not isinstance(index, AbstractDataSource):
32             raise RuntimeError(
33                 "Need an array or list of values or a DataSource, got %s instead."
34                 % type(index)
35             )
36 
37         if type(value) in (list, tuple, ndarray):
38             value = ArrayDataSource(array(value))
39         elif not isinstance(value, AbstractDataSource):
40             raise RuntimeError(
41                 "Need an array or list of values or a DataSource, got %s instead."
42                 % type(index)
43             )
44 
45         return index, value
46     else:
47         raise RuntimeError("Unable to create datasources.")
48 
49 
50 def create_scatter_plot(
51     data=[],
52     index_bounds=None,
53     value_bounds=None,
54     orientation="h",
55     color="green",
56     marker="square",
57     marker_size=4,
58     bgcolor="transparent",
59     outline_color="black",
60     border_visible=True,
61     add_grid=False,
62     add_axis=False,
63     index_sort="none",
64     **renderer_traits
65 ):
66     """Creates a ScatterPlot renderer from a single Nx2 data array or a tuple
67     of two length-N 1-D arrays.  The data must be sorted on the index if any
68     reverse-mapping tools are to be used.
69 
70     Pre-existing "index" and "value" datasources can be passed in.
71     """
72 
73     index, value = _create_data_sources(data)
74 
75     if index_bounds is not None:
76         index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])
77     else:
78         index_range = DataRange1D()
79     index_range.add(index)
80     index_mapper = LinearMapper(range=index_range)
81 
82     if value_bounds is not None:
83         value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])
84     else:
85         value_range = DataRange1D()
86     value_range.add(value)
87     value_mapper = LinearMapper(range=value_range)
88 
89     plot = ScatterPlot(
90         index=index,
91         value=value,
92         index_mapper=index_mapper,
93         value_mapper=value_mapper,
94         orientation=orientation,
95         marker=marker,
96         marker_size=marker_size,
97         color=color,
98         bgcolor=bgcolor,
99         outline_color=outline_color,
100         border_visible=border_visible,
101         **renderer_traits
102     )
103 
104     if add_grid:
105         add_default_grids(plot, orientation)
106     if add_axis:
107         add_default_axes(plot, orientation)
108     return plot
109 
110 
111 def create_line_plot(
112     data=[],
113     index_bounds=None,
114     value_bounds=None,
115     orientation="h",
116     color="red",
117     width=1.0,
118     dash="solid",
119     value_mapper_class=LinearMapper,
120     bgcolor="transparent",
121     border_visible=False,
122     add_grid=False,
123     add_axis=False,
124     index_sort="none",
125     **renderer_traits
126 ):
127     """Creates a LinePlot renderer from a single Nx2 data array or a tuple of
128     two length-N 1-D arrays.  The data must be sorted on the index if any
129     reverse-mapping tools are to be used.
130 
131     Pre-existing "index" and "value" datasources can be passed in.
132     """
133     index, value = _create_data_sources(data, index_sort)
134 
135     if index_bounds is not None:
136         index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])
137     else:
138         index_range = DataRange1D()
139     index_range.add(index)
140     index_mapper = LinearMapper(range=index_range)
141 
142     if value_bounds is not None:
143         value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])
144     else:
145         value_range = DataRange1D()
146     value_range.add(value)
147     value_mapper = value_mapper_class(range=value_range)
148 
149     plot = LinePlot(
150         index=index,
151         value=value,
152         index_mapper=index_mapper,
153         value_mapper=value_mapper,
154         orientation=orientation,
155         color=color,
156         bgcolor=bgcolor,
157         line_width=width,
158         line_style=dash,
159         border_visible=border_visible,
160         **renderer_traits
161     )
162 
163     if add_grid:
164         add_default_grids(plot, orientation)
165     if add_axis:
166         add_default_axes(plot, orientation)
167     return plot
168 
169 
170 def create_bar_plot(
171     data=[],
172     index_bounds=None,
173     value_bounds=None,
174     orientation="h",
175     color="red",
176     bar_width=10.0,
177     value_mapper_class=LinearMapper,
178     line_color="black",
179     fill_color="red",
180     line_width=1,
181     bgcolor="transparent",
182     border_visible=False,
183     antialias=True,
184     add_grid=False,
185     add_axis=False,
186     **renderer_traits
187 ):
188     """Creates a BarPlot renderer from a single Nx2 data array or a tuple of
189     two length-N 1-D arrays.  The data must be sorted on the index if any
190     reverse-mapping tools are to be used.
191 
192     Pre-existing "index" and "value" datasources can be passed in.
193     """
194     index, value = _create_data_sources(data)
195 
196     if index_bounds is not None:
197         index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])
198     else:
199         index_range = DataRange1D()
200     index_range.add(index)
201     index_mapper = LinearMapper(range=index_range)
202 
203     if value_bounds is not None:
204         value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])
205     else:
206         value_range = DataRange1D()
207     value_range.add(value)
208     value_mapper = value_mapper_class(range=value_range)
209 
210     # Create the plot
211     plot = BarPlot(
212         index=index,
213         value=value,
214         value_mapper=value_mapper,
215         index_mapper=index_mapper,
216         orientation=orientation,
217         line_color=line_color,
218         fill_color=fill_color,
219         line_width=line_width,
220         bar_width=bar_width,
221         antialias=antialias,
222         **renderer_traits
223     )
224 
225     if add_grid:
226         add_default_grids(plot, orientation)
227     if add_axis:
228         add_default_axes(plot, orientation)
229     return plot
230 
231 
232 def create_polar_plot(
233     data,
234     orientation="h",
235     color="black",
236     width=1.0,
237     dash="solid",
238     grid="dot",
239     value_mapper_class=PolarMapper,
240     **renderer_traits
241 ):
242     """Creates a polar plot renderer from a single Nx2 data array or a tuple
243     of two length-N 1-D arrays.  The data must be sorted on the index if any
244     reverse-mapping tools are to be used.
245 
246     Pre-existing "index" and "value" datasources can be passed in.
247     """
248     if (type(data) != ndarray) and (len(data) == 2):
249         data = transpose(array(data))
250 
251     r_data, t_data = transpose(data)
252     index_data = r_data * cos(t_data)
253     value_data = r_data * sin(t_data)
254 
255     index = ArrayDataSource(index_data, sort_order="ascending")
256     # Typically the value data is unsorted
257     value = ArrayDataSource(value_data)
258 
259     index_range = DataRange1D()
260     index_range.add(index)
261     index_mapper = PolarMapper(range=index_range)
262 
263     value_range = DataRange1D()
264     value_range.add(value)
265     value_mapper = value_mapper_class(range=value_range)
266 
267     plot = PolarLineRenderer(
268         index=index,
269         value=value,
270         index_mapper=index_mapper,
271         value_mapper=value_mapper,
272         orientation=orientation,
273         color=color,
274         line_width=width,
275         line_style=dash,
276         grid_style=grid,
277         **renderer_traits
278     )
279 
280     return plot
281 
282 
283 def add_default_axes(
284     plot, orientation="normal", vtitle="", htitle="", axis_class=PlotAxis
285 ):
286     """
287     Creates left and bottom axes for a plot.  Assumes that the index is
288     horizontal and value is vertical by default; set *orientation* to
289     something other than "normal" if they are flipped.
290     """
291     if orientation in ("normal", "h"):
292         v_mapper = plot.value_mapper
293         h_mapper = plot.index_mapper
294     else:
295         v_mapper = plot.index_mapper
296         h_mapper = plot.value_mapper
297 
298     left = axis_class(
299         orientation="left", title=vtitle, mapper=v_mapper, component=plot
300     )
301 
302     bottom = axis_class(
303         orientation="bottom", title=htitle, mapper=h_mapper, component=plot
304     )
305 
306     plot.underlays.append(left)
307     plot.underlays.append(bottom)
308     return left, bottom
309 
310 
311 def add_default_grids(plot, orientation="normal"):
312     """
313     Creates horizontal and vertical gridlines for a plot.  Assumes that the
314     index is horizontal and value is vertical by default; set orientation to
315     something other than "normal" if they are flipped.
316     """
317     if orientation in ("normal", "h"):
318         v_mapper = plot.index_mapper
319         h_mapper = plot.value_mapper
320     else:
321         v_mapper = plot.value_mapper
322         h_mapper = plot.index_mapper
323 
324     vgrid = PlotGrid(
325         mapper=v_mapper,
326         orientation="vertical",
327         component=plot,
328         line_color="lightgray",
329         line_style="dot",
330     )
331 
332     hgrid = PlotGrid(
333         mapper=h_mapper,
334         orientation="horizontal",
335         component=plot,
336         line_color="lightgray",
337         line_style="dot",
338     )
339 
340     plot.underlays.append(vgrid)
341     plot.underlays.append(hgrid)
342     return hgrid, vgrid
343
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/chaco/plot_factory.py b/chaco/plot_factory.py
--- a/chaco/plot_factory.py
+++ b/chaco/plot_factory.py
@@ -48,7 +48,7 @@
 
 
 def create_scatter_plot(
-    data=[],
+    data=None,
     index_bounds=None,
     value_bounds=None,
     orientation="h",
@@ -69,6 +69,8 @@
 
     Pre-existing "index" and "value" datasources can be passed in.
     """
+    if data is None:
+        data = []
 
     index, value = _create_data_sources(data)
 
@@ -109,7 +111,7 @@
 
 
 def create_line_plot(
-    data=[],
+    data=None,
     index_bounds=None,
     value_bounds=None,
     orientation="h",
@@ -130,6 +132,9 @@
 
     Pre-existing "index" and "value" datasources can be passed in.
     """
+    if data is None:
+        data = []
+
     index, value = _create_data_sources(data, index_sort)
 
     if index_bounds is not None:
@@ -168,7 +173,7 @@
 
 
 def create_bar_plot(
-    data=[],
+    data=None,
     index_bounds=None,
     value_bounds=None,
     orientation="h",
@@ -191,6 +196,9 @@
 
     Pre-existing "index" and "value" datasources can be passed in.
     """
+    if data is None:
+        data = []
+
     index, value = _create_data_sources(data)
 
     if index_bounds is not None:

{"golden_diff": "diff --git a/chaco/plot_factory.py b/chaco/plot_factory.py\n--- a/chaco/plot_factory.py\n+++ b/chaco/plot_factory.py\n@@ -48,7 +48,7 @@\n \n \n def create_scatter_plot(\n-    data=[],\n+    data=None,\n     index_bounds=None,\n     value_bounds=None,\n     orientation=\"h\",\n@@ -69,6 +69,8 @@\n \n     Pre-existing \"index\" and \"value\" datasources can be passed in.\n     \"\"\"\n+    if data is None:\n+        data = []\n \n     index, value = _create_data_sources(data)\n \n@@ -109,7 +111,7 @@\n \n \n def create_line_plot(\n-    data=[],\n+    data=None,\n     index_bounds=None,\n     value_bounds=None,\n     orientation=\"h\",\n@@ -130,6 +132,9 @@\n \n     Pre-existing \"index\" and \"value\" datasources can be passed in.\n     \"\"\"\n+    if data is None:\n+        data = []\n+\n     index, value = _create_data_sources(data, index_sort)\n \n     if index_bounds is not None:\n@@ -168,7 +173,7 @@\n \n \n def create_bar_plot(\n-    data=[],\n+    data=None,\n     index_bounds=None,\n     value_bounds=None,\n     orientation=\"h\",\n@@ -191,6 +196,9 @@\n \n     Pre-existing \"index\" and \"value\" datasources can be passed in.\n     \"\"\"\n+    if data is None:\n+        data = []\n+\n     index, value = _create_data_sources(data)\n \n     if index_bounds is not None:\n", "issue": "Replace mutable default argument in plot_factory create_*_plot functions\nReplace the use of mutable default `data` argument to the `create_*_plot` functions in the `plot_factory` module.\r\n\r\nhttps://github.com/enthought/chaco/blob/ef7227706642f7d26042717ad9b60648d7572068/chaco/plot_factory.py#L43\r\nhttps://github.com/enthought/chaco/blob/ef7227706642f7d26042717ad9b60648d7572068/chaco/plot_factory.py#L91\r\nhttps://github.com/enthought/chaco/blob/ef7227706642f7d26042717ad9b60648d7572068/chaco/plot_factory.py#L136\r\n\r\n\n", "before_files": [{"content": "\"\"\"\nContains convenience functions to create ready-made PlotRenderer instances of\nvarious types.\n\"\"\"\n\nfrom numpy import array, ndarray, transpose, cos, sin\n\n# Local relative imports\nfrom .abstract_data_source import AbstractDataSource\nfrom .array_data_source import ArrayDataSource\nfrom .axis import PlotAxis\nfrom .barplot import BarPlot\nfrom .data_range_1d import DataRange1D\nfrom .grid import PlotGrid\nfrom .linear_mapper import LinearMapper\nfrom .scatterplot import ScatterPlot\nfrom .polar_mapper import PolarMapper\nfrom .lineplot import LinePlot\nfrom .polar_line_renderer import PolarLineRenderer\n\n\ndef _create_data_sources(data, index_sort=\"none\"):\n    \"\"\"\n    Returns datasources for index and value based on the inputs.  Assumes that\n    the index data is unsorted unless otherwise specified.\n    \"\"\"\n    if (type(data) == ndarray) or (len(data) == 2):\n        index, value = data\n        if type(index) in (list, tuple, ndarray):\n            index = ArrayDataSource(array(index), sort_order=index_sort)\n        elif not isinstance(index, AbstractDataSource):\n            raise RuntimeError(\n                \"Need an array or list of values or a DataSource, got %s instead.\"\n                % type(index)\n            )\n\n        if type(value) in (list, tuple, ndarray):\n            value = ArrayDataSource(array(value))\n        elif not isinstance(value, AbstractDataSource):\n            raise RuntimeError(\n                \"Need an array or list of values or a DataSource, got %s instead.\"\n                % type(index)\n            )\n\n        return index, value\n    else:\n        raise RuntimeError(\"Unable to create datasources.\")\n\n\ndef create_scatter_plot(\n    data=[],\n    index_bounds=None,\n    value_bounds=None,\n    orientation=\"h\",\n    color=\"green\",\n    marker=\"square\",\n    marker_size=4,\n    bgcolor=\"transparent\",\n    outline_color=\"black\",\n    border_visible=True,\n    add_grid=False,\n    add_axis=False,\n    index_sort=\"none\",\n    **renderer_traits\n):\n    \"\"\"Creates a ScatterPlot renderer from a single Nx2 data array or a tuple\n    of two length-N 1-D arrays.  The data must be sorted on the index if any\n    reverse-mapping tools are to be used.\n\n    Pre-existing \"index\" and \"value\" datasources can be passed in.\n    \"\"\"\n\n    index, value = _create_data_sources(data)\n\n    if index_bounds is not None:\n        index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])\n    else:\n        index_range = DataRange1D()\n    index_range.add(index)\n    index_mapper = LinearMapper(range=index_range)\n\n    if value_bounds is not None:\n        value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])\n    else:\n        value_range = DataRange1D()\n    value_range.add(value)\n    value_mapper = LinearMapper(range=value_range)\n\n    plot = ScatterPlot(\n        index=index,\n        value=value,\n        index_mapper=index_mapper,\n        value_mapper=value_mapper,\n        orientation=orientation,\n        marker=marker,\n        marker_size=marker_size,\n        color=color,\n        bgcolor=bgcolor,\n        outline_color=outline_color,\n        border_visible=border_visible,\n        **renderer_traits\n    )\n\n    if add_grid:\n        add_default_grids(plot, orientation)\n    if add_axis:\n        add_default_axes(plot, orientation)\n    return plot\n\n\ndef create_line_plot(\n    data=[],\n    index_bounds=None,\n    value_bounds=None,\n    orientation=\"h\",\n    color=\"red\",\n    width=1.0,\n    dash=\"solid\",\n    value_mapper_class=LinearMapper,\n    bgcolor=\"transparent\",\n    border_visible=False,\n    add_grid=False,\n    add_axis=False,\n    index_sort=\"none\",\n    **renderer_traits\n):\n    \"\"\"Creates a LinePlot renderer from a single Nx2 data array or a tuple of\n    two length-N 1-D arrays.  The data must be sorted on the index if any\n    reverse-mapping tools are to be used.\n\n    Pre-existing \"index\" and \"value\" datasources can be passed in.\n    \"\"\"\n    index, value = _create_data_sources(data, index_sort)\n\n    if index_bounds is not None:\n        index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])\n    else:\n        index_range = DataRange1D()\n    index_range.add(index)\n    index_mapper = LinearMapper(range=index_range)\n\n    if value_bounds is not None:\n        value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])\n    else:\n        value_range = DataRange1D()\n    value_range.add(value)\n    value_mapper = value_mapper_class(range=value_range)\n\n    plot = LinePlot(\n        index=index,\n        value=value,\n        index_mapper=index_mapper,\n        value_mapper=value_mapper,\n        orientation=orientation,\n        color=color,\n        bgcolor=bgcolor,\n        line_width=width,\n        line_style=dash,\n        border_visible=border_visible,\n        **renderer_traits\n    )\n\n    if add_grid:\n        add_default_grids(plot, orientation)\n    if add_axis:\n        add_default_axes(plot, orientation)\n    return plot\n\n\ndef create_bar_plot(\n    data=[],\n    index_bounds=None,\n    value_bounds=None,\n    orientation=\"h\",\n    color=\"red\",\n    bar_width=10.0,\n    value_mapper_class=LinearMapper,\n    line_color=\"black\",\n    fill_color=\"red\",\n    line_width=1,\n    bgcolor=\"transparent\",\n    border_visible=False,\n    antialias=True,\n    add_grid=False,\n    add_axis=False,\n    **renderer_traits\n):\n    \"\"\"Creates a BarPlot renderer from a single Nx2 data array or a tuple of\n    two length-N 1-D arrays.  The data must be sorted on the index if any\n    reverse-mapping tools are to be used.\n\n    Pre-existing \"index\" and \"value\" datasources can be passed in.\n    \"\"\"\n    index, value = _create_data_sources(data)\n\n    if index_bounds is not None:\n        index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])\n    else:\n        index_range = DataRange1D()\n    index_range.add(index)\n    index_mapper = LinearMapper(range=index_range)\n\n    if value_bounds is not None:\n        value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])\n    else:\n        value_range = DataRange1D()\n    value_range.add(value)\n    value_mapper = value_mapper_class(range=value_range)\n\n    # Create the plot\n    plot = BarPlot(\n        index=index,\n        value=value,\n        value_mapper=value_mapper,\n        index_mapper=index_mapper,\n        orientation=orientation,\n        line_color=line_color,\n        fill_color=fill_color,\n        line_width=line_width,\n        bar_width=bar_width,\n        antialias=antialias,\n        **renderer_traits\n    )\n\n    if add_grid:\n        add_default_grids(plot, orientation)\n    if add_axis:\n        add_default_axes(plot, orientation)\n    return plot\n\n\ndef create_polar_plot(\n    data,\n    orientation=\"h\",\n    color=\"black\",\n    width=1.0,\n    dash=\"solid\",\n    grid=\"dot\",\n    value_mapper_class=PolarMapper,\n    **renderer_traits\n):\n    \"\"\"Creates a polar plot renderer from a single Nx2 data array or a tuple\n    of two length-N 1-D arrays.  The data must be sorted on the index if any\n    reverse-mapping tools are to be used.\n\n    Pre-existing \"index\" and \"value\" datasources can be passed in.\n    \"\"\"\n    if (type(data) != ndarray) and (len(data) == 2):\n        data = transpose(array(data))\n\n    r_data, t_data = transpose(data)\n    index_data = r_data * cos(t_data)\n    value_data = r_data * sin(t_data)\n\n    index = ArrayDataSource(index_data, sort_order=\"ascending\")\n    # Typically the value data is unsorted\n    value = ArrayDataSource(value_data)\n\n    index_range = DataRange1D()\n    index_range.add(index)\n    index_mapper = PolarMapper(range=index_range)\n\n    value_range = DataRange1D()\n    value_range.add(value)\n    value_mapper = value_mapper_class(range=value_range)\n\n    plot = PolarLineRenderer(\n        index=index,\n        value=value,\n        index_mapper=index_mapper,\n        value_mapper=value_mapper,\n        orientation=orientation,\n        color=color,\n        line_width=width,\n        line_style=dash,\n        grid_style=grid,\n        **renderer_traits\n    )\n\n    return plot\n\n\ndef add_default_axes(\n    plot, orientation=\"normal\", vtitle=\"\", htitle=\"\", axis_class=PlotAxis\n):\n    \"\"\"\n    Creates left and bottom axes for a plot.  Assumes that the index is\n    horizontal and value is vertical by default; set *orientation* to\n    something other than \"normal\" if they are flipped.\n    \"\"\"\n    if orientation in (\"normal\", \"h\"):\n        v_mapper = plot.value_mapper\n        h_mapper = plot.index_mapper\n    else:\n        v_mapper = plot.index_mapper\n        h_mapper = plot.value_mapper\n\n    left = axis_class(\n        orientation=\"left\", title=vtitle, mapper=v_mapper, component=plot\n    )\n\n    bottom = axis_class(\n        orientation=\"bottom\", title=htitle, mapper=h_mapper, component=plot\n    )\n\n    plot.underlays.append(left)\n    plot.underlays.append(bottom)\n    return left, bottom\n\n\ndef add_default_grids(plot, orientation=\"normal\"):\n    \"\"\"\n    Creates horizontal and vertical gridlines for a plot.  Assumes that the\n    index is horizontal and value is vertical by default; set orientation to\n    something other than \"normal\" if they are flipped.\n    \"\"\"\n    if orientation in (\"normal\", \"h\"):\n        v_mapper = plot.index_mapper\n        h_mapper = plot.value_mapper\n    else:\n        v_mapper = plot.value_mapper\n        h_mapper = plot.index_mapper\n\n    vgrid = PlotGrid(\n        mapper=v_mapper,\n        orientation=\"vertical\",\n        component=plot,\n        line_color=\"lightgray\",\n        line_style=\"dot\",\n    )\n\n    hgrid = PlotGrid(\n        mapper=h_mapper,\n        orientation=\"horizontal\",\n        component=plot,\n        line_color=\"lightgray\",\n        line_style=\"dot\",\n    )\n\n    plot.underlays.append(vgrid)\n    plot.underlays.append(hgrid)\n    return hgrid, vgrid\n", "path": "chaco/plot_factory.py"}], "after_files": [{"content": "\"\"\"\nContains convenience functions to create ready-made PlotRenderer instances of\nvarious types.\n\"\"\"\n\nfrom numpy import array, ndarray, transpose, cos, sin\n\n# Local relative imports\nfrom .abstract_data_source import AbstractDataSource\nfrom .array_data_source import ArrayDataSource\nfrom .axis import PlotAxis\nfrom .barplot import BarPlot\nfrom .data_range_1d import DataRange1D\nfrom .grid import PlotGrid\nfrom .linear_mapper import LinearMapper\nfrom .scatterplot import ScatterPlot\nfrom .polar_mapper import PolarMapper\nfrom .lineplot import LinePlot\nfrom .polar_line_renderer import PolarLineRenderer\n\n\ndef _create_data_sources(data, index_sort=\"none\"):\n    \"\"\"\n    Returns datasources for index and value based on the inputs.  Assumes that\n    the index data is unsorted unless otherwise specified.\n    \"\"\"\n    if (type(data) == ndarray) or (len(data) == 2):\n        index, value = data\n        if type(index) in (list, tuple, ndarray):\n            index = ArrayDataSource(array(index), sort_order=index_sort)\n        elif not isinstance(index, AbstractDataSource):\n            raise RuntimeError(\n                \"Need an array or list of values or a DataSource, got %s instead.\"\n                % type(index)\n            )\n\n        if type(value) in (list, tuple, ndarray):\n            value = ArrayDataSource(array(value))\n        elif not isinstance(value, AbstractDataSource):\n            raise RuntimeError(\n                \"Need an array or list of values or a DataSource, got %s instead.\"\n                % type(index)\n            )\n\n        return index, value\n    else:\n        raise RuntimeError(\"Unable to create datasources.\")\n\n\ndef create_scatter_plot(\n    data=None,\n    index_bounds=None,\n    value_bounds=None,\n    orientation=\"h\",\n    color=\"green\",\n    marker=\"square\",\n    marker_size=4,\n    bgcolor=\"transparent\",\n    outline_color=\"black\",\n    border_visible=True,\n    add_grid=False,\n    add_axis=False,\n    index_sort=\"none\",\n    **renderer_traits\n):\n    \"\"\"Creates a ScatterPlot renderer from a single Nx2 data array or a tuple\n    of two length-N 1-D arrays.  The data must be sorted on the index if any\n    reverse-mapping tools are to be used.\n\n    Pre-existing \"index\" and \"value\" datasources can be passed in.\n    \"\"\"\n    if data is None:\n        data = []\n\n    index, value = _create_data_sources(data)\n\n    if index_bounds is not None:\n        index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])\n    else:\n        index_range = DataRange1D()\n    index_range.add(index)\n    index_mapper = LinearMapper(range=index_range)\n\n    if value_bounds is not None:\n        value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])\n    else:\n        value_range = DataRange1D()\n    value_range.add(value)\n    value_mapper = LinearMapper(range=value_range)\n\n    plot = ScatterPlot(\n        index=index,\n        value=value,\n        index_mapper=index_mapper,\n        value_mapper=value_mapper,\n        orientation=orientation,\n        marker=marker,\n        marker_size=marker_size,\n        color=color,\n        bgcolor=bgcolor,\n        outline_color=outline_color,\n        border_visible=border_visible,\n        **renderer_traits\n    )\n\n    if add_grid:\n        add_default_grids(plot, orientation)\n    if add_axis:\n        add_default_axes(plot, orientation)\n    return plot\n\n\ndef create_line_plot(\n    data=None,\n    index_bounds=None,\n    value_bounds=None,\n    orientation=\"h\",\n    color=\"red\",\n    width=1.0,\n    dash=\"solid\",\n    value_mapper_class=LinearMapper,\n    bgcolor=\"transparent\",\n    border_visible=False,\n    add_grid=False,\n    add_axis=False,\n    index_sort=\"none\",\n    **renderer_traits\n):\n    \"\"\"Creates a LinePlot renderer from a single Nx2 data array or a tuple of\n    two length-N 1-D arrays.  The data must be sorted on the index if any\n    reverse-mapping tools are to be used.\n\n    Pre-existing \"index\" and \"value\" datasources can be passed in.\n    \"\"\"\n    if data is None:\n        data = []\n\n    index, value = _create_data_sources(data, index_sort)\n\n    if index_bounds is not None:\n        index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])\n    else:\n        index_range = DataRange1D()\n    index_range.add(index)\n    index_mapper = LinearMapper(range=index_range)\n\n    if value_bounds is not None:\n        value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])\n    else:\n        value_range = DataRange1D()\n    value_range.add(value)\n    value_mapper = value_mapper_class(range=value_range)\n\n    plot = LinePlot(\n        index=index,\n        value=value,\n        index_mapper=index_mapper,\n        value_mapper=value_mapper,\n        orientation=orientation,\n        color=color,\n        bgcolor=bgcolor,\n        line_width=width,\n        line_style=dash,\n        border_visible=border_visible,\n        **renderer_traits\n    )\n\n    if add_grid:\n        add_default_grids(plot, orientation)\n    if add_axis:\n        add_default_axes(plot, orientation)\n    return plot\n\n\ndef create_bar_plot(\n    data=None,\n    index_bounds=None,\n    value_bounds=None,\n    orientation=\"h\",\n    color=\"red\",\n    bar_width=10.0,\n    value_mapper_class=LinearMapper,\n    line_color=\"black\",\n    fill_color=\"red\",\n    line_width=1,\n    bgcolor=\"transparent\",\n    border_visible=False,\n    antialias=True,\n    add_grid=False,\n    add_axis=False,\n    **renderer_traits\n):\n    \"\"\"Creates a BarPlot renderer from a single Nx2 data array or a tuple of\n    two length-N 1-D arrays.  The data must be sorted on the index if any\n    reverse-mapping tools are to be used.\n\n    Pre-existing \"index\" and \"value\" datasources can be passed in.\n    \"\"\"\n    if data is None:\n        data = []\n\n    index, value = _create_data_sources(data)\n\n    if index_bounds is not None:\n        index_range = DataRange1D(low=index_bounds[0], high=index_bounds[1])\n    else:\n        index_range = DataRange1D()\n    index_range.add(index)\n    index_mapper = LinearMapper(range=index_range)\n\n    if value_bounds is not None:\n        value_range = DataRange1D(low=value_bounds[0], high=value_bounds[1])\n    else:\n        value_range = DataRange1D()\n    value_range.add(value)\n    value_mapper = value_mapper_class(range=value_range)\n\n    # Create the plot\n    plot = BarPlot(\n        index=index,\n        value=value,\n        value_mapper=value_mapper,\n        index_mapper=index_mapper,\n        orientation=orientation,\n        line_color=line_color,\n        fill_color=fill_color,\n        line_width=line_width,\n        bar_width=bar_width,\n        antialias=antialias,\n        **renderer_traits\n    )\n\n    if add_grid:\n        add_default_grids(plot, orientation)\n    if add_axis:\n        add_default_axes(plot, orientation)\n    return plot\n\n\ndef create_polar_plot(\n    data,\n    orientation=\"h\",\n    color=\"black\",\n    width=1.0,\n    dash=\"solid\",\n    grid=\"dot\",\n    value_mapper_class=PolarMapper,\n    **renderer_traits\n):\n    \"\"\"Creates a polar plot renderer from a single Nx2 data array or a tuple\n    of two length-N 1-D arrays.  The data must be sorted on the index if any\n    reverse-mapping tools are to be used.\n\n    Pre-existing \"index\" and \"value\" datasources can be passed in.\n    \"\"\"\n    if (type(data) != ndarray) and (len(data) == 2):\n        data = transpose(array(data))\n\n    r_data, t_data = transpose(data)\n    index_data = r_data * cos(t_data)\n    value_data = r_data * sin(t_data)\n\n    index = ArrayDataSource(index_data, sort_order=\"ascending\")\n    # Typically the value data is unsorted\n    value = ArrayDataSource(value_data)\n\n    index_range = DataRange1D()\n    index_range.add(index)\n    index_mapper = PolarMapper(range=index_range)\n\n    value_range = DataRange1D()\n    value_range.add(value)\n    value_mapper = value_mapper_class(range=value_range)\n\n    plot = PolarLineRenderer(\n        index=index,\n        value=value,\n        index_mapper=index_mapper,\n        value_mapper=value_mapper,\n        orientation=orientation,\n        color=color,\n        line_width=width,\n        line_style=dash,\n        grid_style=grid,\n        **renderer_traits\n    )\n\n    return plot\n\n\ndef add_default_axes(\n    plot, orientation=\"normal\", vtitle=\"\", htitle=\"\", axis_class=PlotAxis\n):\n    \"\"\"\n    Creates left and bottom axes for a plot.  Assumes that the index is\n    horizontal and value is vertical by default; set *orientation* to\n    something other than \"normal\" if they are flipped.\n    \"\"\"\n    if orientation in (\"normal\", \"h\"):\n        v_mapper = plot.value_mapper\n        h_mapper = plot.index_mapper\n    else:\n        v_mapper = plot.index_mapper\n        h_mapper = plot.value_mapper\n\n    left = axis_class(\n        orientation=\"left\", title=vtitle, mapper=v_mapper, component=plot\n    )\n\n    bottom = axis_class(\n        orientation=\"bottom\", title=htitle, mapper=h_mapper, component=plot\n    )\n\n    plot.underlays.append(left)\n    plot.underlays.append(bottom)\n    return left, bottom\n\n\ndef add_default_grids(plot, orientation=\"normal\"):\n    \"\"\"\n    Creates horizontal and vertical gridlines for a plot.  Assumes that the\n    index is horizontal and value is vertical by default; set orientation to\n    something other than \"normal\" if they are flipped.\n    \"\"\"\n    if orientation in (\"normal\", \"h\"):\n        v_mapper = plot.index_mapper\n        h_mapper = plot.value_mapper\n    else:\n        v_mapper = plot.value_mapper\n        h_mapper = plot.index_mapper\n\n    vgrid = PlotGrid(\n        mapper=v_mapper,\n        orientation=\"vertical\",\n        component=plot,\n        line_color=\"lightgray\",\n        line_style=\"dot\",\n    )\n\n    hgrid = PlotGrid(\n        mapper=h_mapper,\n        orientation=\"horizontal\",\n        component=plot,\n        line_color=\"lightgray\",\n        line_style=\"dot\",\n    )\n\n    plot.underlays.append(vgrid)\n    plot.underlays.append(hgrid)\n    return hgrid, vgrid\n", "path": "chaco/plot_factory.py"}]}