From 8d7e0031e612ca3b29240c78a9b3153c38bc7b0d Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Thu, 29 Apr 2021 16:36:47 -0500 Subject: [PATCH 01/12] start of matplotlib_to_chaco --- docs/source/user_manual/index.rst | 1 + .../user_manual/matplotlib_to_chaco.rst | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 docs/source/user_manual/matplotlib_to_chaco.rst diff --git a/docs/source/user_manual/index.rst b/docs/source/user_manual/index.rst index 0874ab029..2104b8f0b 100644 --- a/docs/source/user_manual/index.rst +++ b/docs/source/user_manual/index.rst @@ -26,3 +26,4 @@ User Guide common_patterns.rst how_do_i.rst faq.rst + matplotlib_to_chaco.rst diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst new file mode 100644 index 000000000..8e6797ff9 --- /dev/null +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -0,0 +1,50 @@ +.. _matplotlib2chaco: + +############################## +Matplotlib To Chaco Cheatsheet +############################## +As mentioned in the :ref:`Chaco Tutorial `, +`matplotlib `_ and Chaco have different +approaches to plotting (script-oriented vs. application oriented). However, new +users of chaco who have worked with matplotlib in the past may find it useful +to map code into the "equivalent" in the other. + +The following table list various plotting related operations one might want to +perform along with how you could go abou doing that using either Chaco or +Matplotlib. + ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| What | matplotlib | Chaco | ++========================+===============================+========================================================================+ +| Plot lines | `ax.plot(x, y)` | `p.plot(('x', 'y'))` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| x label | `ax.set_xlabel('Time')` | `p.x_axis.title = 'Time'` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| y label | `ax.set_ylabel('Value')` | `p.y_axis.title = 'Value'` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Title | `ax.set_title(title)` | `p.title = title` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| X limits | `ax.set_xlim((low, high))` | `p.index_range.low_setting = LOW` | +| | | `p.index_range.high_setting = HIGH` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Y limits | `ax.set_ylim((low, high))` | `p.value_range.low_setting = LOW` | +| | | `p.value_range.high_setting = HIGH` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Label lines for legend | `ax.plot(…, label=label)` | `p.plot(…, name=name)` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Add legend | `ax.legend()` | `p.legend.visible = True` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Legend position | `ax.legend(loc='lower left')` | `p.legend_alignment = 'll'` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Background color | | ` p.bgcolor = 'white'` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Show spines | | `p.border_visible = True` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Line width | `ax.plot(linewidth=lw)` | `p.line_width = 1.1` or `p.plot(…, linewidth=lw)` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| X grid | `ax.grid(axis='x')` | `p.x_axis.visible = True` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Y grid | ` ax.grid(axis='y')` | `p.y_axis.visible = True` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ +| Second y ticks | | `line.y_axis.orientation = "right"` | ++------------------------+-------------------------------+------------------------------------------------------------------------+ \ No newline at end of file From 6c7e0efd927ec5db111bef148e7eb70b21f72a39 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Mon, 3 May 2021 12:43:36 -0500 Subject: [PATCH 02/12] fill table and explain ax / p --- .../user_manual/matplotlib_to_chaco.rst | 81 ++++++++++--------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index 8e6797ff9..0d08efce8 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -7,44 +7,49 @@ As mentioned in the :ref:`Chaco Tutorial `, `matplotlib `_ and Chaco have different approaches to plotting (script-oriented vs. application oriented). However, new users of chaco who have worked with matplotlib in the past may find it useful -to map code into the "equivalent" in the other. +to think about mapping "equivalent" code between the two. The following table list various plotting related operations one might want to -perform along with how you could go abou doing that using either Chaco or -Matplotlib. +perform along with how you could go about doing that using either Chaco or +Matplotlib. For Matplotlib code ``ax`` repesents the Axes that what would result from +running ``fig, ax = plt.subplots()`` after importing +``import matplotlib.pyplot as plt``. For more details see the +`matplotlib User's Guide `_. +For Chaco code, ``p`` is the :class:`~.Plot` instance. -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| What | matplotlib | Chaco | -+========================+===============================+========================================================================+ -| Plot lines | `ax.plot(x, y)` | `p.plot(('x', 'y'))` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| x label | `ax.set_xlabel('Time')` | `p.x_axis.title = 'Time'` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| y label | `ax.set_ylabel('Value')` | `p.y_axis.title = 'Value'` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Title | `ax.set_title(title)` | `p.title = title` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| X limits | `ax.set_xlim((low, high))` | `p.index_range.low_setting = LOW` | -| | | `p.index_range.high_setting = HIGH` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Y limits | `ax.set_ylim((low, high))` | `p.value_range.low_setting = LOW` | -| | | `p.value_range.high_setting = HIGH` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Label lines for legend | `ax.plot(…, label=label)` | `p.plot(…, name=name)` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Add legend | `ax.legend()` | `p.legend.visible = True` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Legend position | `ax.legend(loc='lower left')` | `p.legend_alignment = 'll'` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Background color | | ` p.bgcolor = 'white'` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Show spines | | `p.border_visible = True` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Line width | `ax.plot(linewidth=lw)` | `p.line_width = 1.1` or `p.plot(…, linewidth=lw)` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| X grid | `ax.grid(axis='x')` | `p.x_axis.visible = True` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Y grid | ` ax.grid(axis='y')` | `p.y_axis.visible = True` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ -| Second y ticks | | `line.y_axis.orientation = "right"` | -+------------------------+-------------------------------+------------------------------------------------------------------------+ \ No newline at end of file ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| What | matplotlib | Chaco | ++========================+==========================================+========================================================================+ +| Plot lines | `ax.plot(x, y)` | `p.plot(('x', 'y'))` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| x label | `ax.set_xlabel('Time')` | `p.x_axis.title = 'Time'` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| y label | `ax.set_ylabel('Value')` | `p.y_axis.title = 'Value'` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Title | `ax.set_title(title)` | `p.title = title` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| X limits | `ax.set_xlim((low, high))` | `p.index_range.low_setting = LOW` | +| | | `p.index_range.high_setting = HIGH` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Y limits | `ax.set_ylim((low, high))` | `p.value_range.low_setting = LOW` | +| | | `p.value_range.high_setting = HIGH` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Label lines for legend | `ax.plot(…, label=label)` | `p.plot(…, name=name)` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Add legend | `ax.legend()` | `p.legend.visible = True` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Legend position | `ax.legend(loc='lower left')` | `p.legend_alignment = 'll'` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Background color | ax.set_facecolor('white') | `p.bgcolor = 'white'` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Show spines | ax.spines.set_color('black') | `p.border_visible = True` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Line width | `ax.plot(linewidth=lw)` | `p.line_width = 1.1` or `p.plot(…, linewidth=lw)` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| X grid | `ax.grid(axis='x')` | `p.x_axis.visible = True` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Y grid | `ax.grid(axis='y')` | `p.y_axis.visible = True` | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ +| Second y ticks | `ax.yaxis.set_label_position('right')` | `p.y_axis.orientation = "right"` | +| | `ax.yaxis.tick_right()` | | ++------------------------+------------------------------------------+------------------------------------------------------------------------+ From 8e6a8d3596922dcceb6c9c38a34f22601d5a6793 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Mon, 3 May 2021 12:47:00 -0500 Subject: [PATCH 03/12] typo --- docs/source/user_manual/matplotlib_to_chaco.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index 0d08efce8..31cfc8757 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -9,9 +9,9 @@ approaches to plotting (script-oriented vs. application oriented). However, new users of chaco who have worked with matplotlib in the past may find it useful to think about mapping "equivalent" code between the two. -The following table list various plotting related operations one might want to -perform along with how you could go about doing that using either Chaco or -Matplotlib. For Matplotlib code ``ax`` repesents the Axes that what would result from +The following table lists various plotting related operations one might want to +perform along with code for doing that using either Chaco or Matplotlib. For +the Matplotlib code ``ax`` repesents the Axes that what would result from running ``fig, ax = plt.subplots()`` after importing ``import matplotlib.pyplot as plt``. For more details see the `matplotlib User's Guide `_. From 1c58a7a6dc7ecee0da30fdf1257f7fcdc56c7677 Mon Sep 17 00:00:00 2001 From: aaronayres35 <36972686+aaronayres35@users.noreply.github.com> Date: Mon, 3 May 2021 12:48:02 -0500 Subject: [PATCH 04/12] remove extra space --- docs/source/user_manual/matplotlib_to_chaco.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index 31cfc8757..80db92d13 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -10,7 +10,7 @@ users of chaco who have worked with matplotlib in the past may find it useful to think about mapping "equivalent" code between the two. The following table lists various plotting related operations one might want to -perform along with code for doing that using either Chaco or Matplotlib. For +perform along with code for doing that using either Chaco or Matplotlib. For the Matplotlib code ``ax`` repesents the Axes that what would result from running ``fig, ax = plt.subplots()`` after importing ``import matplotlib.pyplot as plt``. For more details see the From 5d75906dc0faf2c28fa9cf2afa17785148ec1478 Mon Sep 17 00:00:00 2001 From: aaronayres35 <36972686+aaronayres35@users.noreply.github.com> Date: Tue, 4 May 2021 06:39:58 -0500 Subject: [PATCH 05/12] Update docs/source/user_manual/matplotlib_to_chaco.rst Co-authored-by: Poruri Sai Rahul --- docs/source/user_manual/matplotlib_to_chaco.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index 80db92d13..61f2f31f8 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -11,8 +11,8 @@ to think about mapping "equivalent" code between the two. The following table lists various plotting related operations one might want to perform along with code for doing that using either Chaco or Matplotlib. For -the Matplotlib code ``ax`` repesents the Axes that what would result from -running ``fig, ax = plt.subplots()`` after importing +the Matplotlib code ``ax`` repesents the Plot Axes +i.e. ``fig, ax = plt.subplots()`` after importing ``import matplotlib.pyplot as plt``. For more details see the `matplotlib User's Guide `_. For Chaco code, ``p`` is the :class:`~.Plot` instance. From e91f818606786fd956569c0f6da8aea1c65a6845 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Tue, 4 May 2021 07:43:52 -0500 Subject: [PATCH 06/12] suggestions from code review --- .../user_manual/matplotlib_to_chaco.rst | 93 +++++++++++-------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index 61f2f31f8..eabff17ae 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -15,41 +15,60 @@ the Matplotlib code ``ax`` repesents the Plot Axes i.e. ``fig, ax = plt.subplots()`` after importing ``import matplotlib.pyplot as plt``. For more details see the `matplotlib User's Guide `_. -For Chaco code, ``p`` is the :class:`~.Plot` instance. +For Chaco code, ``p`` is the :class:`~.Plot` instance. ``x`` and ``y`` are the +data to be plotted. In chaco, this data needs to be wrapped in some +``PlotData`` object. For example, -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| What | matplotlib | Chaco | -+========================+==========================================+========================================================================+ -| Plot lines | `ax.plot(x, y)` | `p.plot(('x', 'y'))` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| x label | `ax.set_xlabel('Time')` | `p.x_axis.title = 'Time'` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| y label | `ax.set_ylabel('Value')` | `p.y_axis.title = 'Value'` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Title | `ax.set_title(title)` | `p.title = title` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| X limits | `ax.set_xlim((low, high))` | `p.index_range.low_setting = LOW` | -| | | `p.index_range.high_setting = HIGH` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Y limits | `ax.set_ylim((low, high))` | `p.value_range.low_setting = LOW` | -| | | `p.value_range.high_setting = HIGH` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Label lines for legend | `ax.plot(…, label=label)` | `p.plot(…, name=name)` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Add legend | `ax.legend()` | `p.legend.visible = True` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Legend position | `ax.legend(loc='lower left')` | `p.legend_alignment = 'll'` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Background color | ax.set_facecolor('white') | `p.bgcolor = 'white'` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Show spines | ax.spines.set_color('black') | `p.border_visible = True` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Line width | `ax.plot(linewidth=lw)` | `p.line_width = 1.1` or `p.plot(…, linewidth=lw)` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| X grid | `ax.grid(axis='x')` | `p.x_axis.visible = True` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Y grid | `ax.grid(axis='y')` | `p.y_axis.visible = True` | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ -| Second y ticks | `ax.yaxis.set_label_position('right')` | `p.y_axis.orientation = "right"` | -| | `ax.yaxis.tick_right()` | | -+------------------------+------------------------------------------+------------------------------------------------------------------------+ +:: + + import numpy as np + x = np.linspace(-2*pi, 2*pi, 100) + y = sin(x) + + # chaco only + pd = ArrayPlotData() + pd.set_data("x", x) + pd.set_data("y", y) + p = Plot(pd) + +Note that in the matplotlib column, ``x`` aand ``y`` represent the data, but +``'x'`` and ``'y'``, such as in "X grid" and "Y Grid" rows are simply options +for the ``axis`` argument. In chaco ``'x'`` and ``'y'`` are the names the +``PlotData`` object associates with numpy arrays ``x`` and ``y``. + ++------------------------+------------------------------------------+------------------------------------------------------+ +| What | matplotlib | Chaco | ++========================+==========================================+======================================================+ +| Plot lines | `ax.plot(x, y)` | `p.plot(('x', 'y'))` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| x label | `ax.set_xlabel('Time')` | `p.x_axis.title = 'Time'` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| y label | `ax.set_ylabel('Value')` | `p.y_axis.title = 'Value'` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Title | `ax.set_title(title)` | `p.title = title` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| X limits | `ax.set_xlim((low, high))` | `p.index_range.low_setting = LOW` | +| | | `p.index_range.high_setting = HIGH` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Y limits | `ax.set_ylim((low, high))` | `p.value_range.low_setting = LOW` | +| | | `p.value_range.high_setting = HIGH` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Label lines for legend | `ax.plot(…, label=label)` | `p.plot(…, name=name)` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Add legend | `ax.legend()` | `p.legend.visible = True` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Legend position | `ax.legend(loc='lower left')` `p.legend_alignment = 'll'` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Background color | ax.set_facecolor('white') | `p.bgcolor = 'white'` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Show spines | ax.spines.set_color('black') | `p.border_visible = True` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Line width | `ax.plot(linewidth=lw)` | `p.line_width = 1.1` or `p.plot(…, linewidth=lw)` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| X grid | `ax.grid(axis='x')` | `p.x_axis.visible = True` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Y grid | `ax.grid(axis='y')` | `p.y_axis.visible = True` | ++------------------------+------------------------------------------+------------------------------------------------------+ +| Second y ticks | `ax.yaxis.set_label_position('right')` | `p.y_axis.orientation = "right"` | +| | `ax.yaxis.tick_right()` | | ++------------------------+------------------------------------------+------------------------------------------------------+ From 49ab111ce206f6206862b114759de18bc4b5620d Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Tue, 4 May 2021 08:45:33 -0500 Subject: [PATCH 07/12] use list-table --- .../user_manual/matplotlib_to_chaco.rst | 97 +++++++++++-------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index eabff17ae..7a7c071e6 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -31,44 +31,61 @@ data to be plotted. In chaco, this data needs to be wrapped in some pd.set_data("y", y) p = Plot(pd) -Note that in the matplotlib column, ``x`` aand ``y`` represent the data, but -``'x'`` and ``'y'``, such as in "X grid" and "Y Grid" rows are simply options -for the ``axis`` argument. In chaco ``'x'`` and ``'y'`` are the names the -``PlotData`` object associates with numpy arrays ``x`` and ``y``. +Note that in the matplotlib column, ``x`` and ``y`` represent the data, but +``'x'`` and ``'y'``, such as in the "X grid" and "Y Grid" rows are simply +options for the ``axis`` argument. In chaco ``'x'`` and ``'y'`` are the names +the ``PlotData`` object associates with numpy arrays ``x`` and ``y``. -+------------------------+------------------------------------------+------------------------------------------------------+ -| What | matplotlib | Chaco | -+========================+==========================================+======================================================+ -| Plot lines | `ax.plot(x, y)` | `p.plot(('x', 'y'))` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| x label | `ax.set_xlabel('Time')` | `p.x_axis.title = 'Time'` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| y label | `ax.set_ylabel('Value')` | `p.y_axis.title = 'Value'` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Title | `ax.set_title(title)` | `p.title = title` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| X limits | `ax.set_xlim((low, high))` | `p.index_range.low_setting = LOW` | -| | | `p.index_range.high_setting = HIGH` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Y limits | `ax.set_ylim((low, high))` | `p.value_range.low_setting = LOW` | -| | | `p.value_range.high_setting = HIGH` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Label lines for legend | `ax.plot(…, label=label)` | `p.plot(…, name=name)` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Add legend | `ax.legend()` | `p.legend.visible = True` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Legend position | `ax.legend(loc='lower left')` `p.legend_alignment = 'll'` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Background color | ax.set_facecolor('white') | `p.bgcolor = 'white'` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Show spines | ax.spines.set_color('black') | `p.border_visible = True` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Line width | `ax.plot(linewidth=lw)` | `p.line_width = 1.1` or `p.plot(…, linewidth=lw)` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| X grid | `ax.grid(axis='x')` | `p.x_axis.visible = True` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Y grid | `ax.grid(axis='y')` | `p.y_axis.visible = True` | -+------------------------+------------------------------------------+------------------------------------------------------+ -| Second y ticks | `ax.yaxis.set_label_position('right')` | `p.y_axis.orientation = "right"` | -| | `ax.yaxis.tick_right()` | | -+------------------------+------------------------------------------+------------------------------------------------------+ +.. list-table:: Matplotlib To Chaco Cheatsheet + :widths: 25 40 50 + :header-rows: 1 + + * - What + - Matplotlib + - Chaco + * - Plot lines + - `ax.plot(x, y)` + - `p.plot(('x', 'y'))` + * - x label + - `ax.set_xlabel('Time')` + - `p.x_axis.title = 'Time'` + * - y label + - `ax.set_ylabel('Value')` + - `p.y_axis.title = 'Value'` + * - Title + - `ax.set_title(title)` + - `p.title = title` + * - X limits + - `ax.set_xlim((low, high))` + - `p.index_range.low_setting = LOW` `p.index_range.high_setting = HIGH` + * - Y limits + - `ax.set_ylim((low, high))` + - `p.value_range.low_setting = LOW` `p.value_range.high_setting = HIGH` + * - Label lines for legend + - `ax.plot(…, label=label)` + - `p.plot(…, name=name)` + * - Add legend + - `ax.legend()` + - `p.legend.visible = True` + * - Legend position + - `ax.legend(loc='lower left')` + - `p.legend_alignment = 'll'` + * - Background color + - `ax.set_facecolor('white')` + - `p.bgcolor = 'white'` + * - Show spines + - `ax.spines.set_color('black')` + - `p.border_visible = True` + * - Line width + - `ax.plot(linewidth=lw)` + - `p.line_width = 1.1` or `p.plot(…, linewidth=lw)` + * - X grid + - `ax.grid(axis='x')` + - `p.x_axis.visible = True` + * - Y grid + - `ax.grid(axis='y')` + - `p.y_axis.visible = True` + * - Second y ticks + - `ax.yaxis.set_label_position('right')` `ax.yaxis.tick_right()` + - `p.y_axis.orientation = "right"` + From 07422556df02d8a7a4d9ced369a05eeed823d8d9 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Wed, 5 May 2021 07:34:56 -0500 Subject: [PATCH 08/12] typos / grammar --- docs/source/user_manual/matplotlib_to_chaco.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index 7a7c071e6..f88dee7f3 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -5,7 +5,7 @@ Matplotlib To Chaco Cheatsheet ############################## As mentioned in the :ref:`Chaco Tutorial `, `matplotlib `_ and Chaco have different -approaches to plotting (script-oriented vs. application oriented). However, new +approaches to plotting (script-oriented vs. application-oriented). However, new users of chaco who have worked with matplotlib in the past may find it useful to think about mapping "equivalent" code between the two. @@ -88,4 +88,3 @@ the ``PlotData`` object associates with numpy arrays ``x`` and ``y``. * - Second y ticks - `ax.yaxis.set_label_position('right')` `ax.yaxis.tick_right()` - `p.y_axis.orientation = "right"` - From 16512d12770b42e9f51925d4bbbb1dbf2abea7b8 Mon Sep 17 00:00:00 2001 From: aaronayres35 <36972686+aaronayres35@users.noreply.github.com> Date: Wed, 5 May 2021 07:35:33 -0500 Subject: [PATCH 09/12] Update docs/source/user_manual/matplotlib_to_chaco.rst Co-authored-by: Poruri Sai Rahul --- docs/source/user_manual/matplotlib_to_chaco.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index f88dee7f3..993c06274 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -16,7 +16,7 @@ i.e. ``fig, ax = plt.subplots()`` after importing ``import matplotlib.pyplot as plt``. For more details see the `matplotlib User's Guide `_. For Chaco code, ``p`` is the :class:`~.Plot` instance. ``x`` and ``y`` are the -data to be plotted. In chaco, this data needs to be wrapped in some +data to be plotted. In chaco, this data needs to be wrapped in a ``PlotData`` object. For example, :: From 84e300513e5db9a92e63e7c9fda0aa0535cec2ef Mon Sep 17 00:00:00 2001 From: aaronayres35 <36972686+aaronayres35@users.noreply.github.com> Date: Wed, 5 May 2021 09:55:11 -0500 Subject: [PATCH 10/12] Apply suggestions from code review Co-authored-by: Alexandre Chabot-Leclerc --- docs/source/user_manual/matplotlib_to_chaco.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index 993c06274..d052570d6 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -1,22 +1,22 @@ .. _matplotlib2chaco: ############################## -Matplotlib To Chaco Cheatsheet +Matplotlib to Chaco Cheatsheet ############################## As mentioned in the :ref:`Chaco Tutorial `, `matplotlib `_ and Chaco have different approaches to plotting (script-oriented vs. application-oriented). However, new -users of chaco who have worked with matplotlib in the past may find it useful +users of Chaco who have worked with matplotlib in the past may find it useful to think about mapping "equivalent" code between the two. The following table lists various plotting related operations one might want to -perform along with code for doing that using either Chaco or Matplotlib. For -the Matplotlib code ``ax`` repesents the Plot Axes +perform along with code for doing that using either Chaco or matplotlib. For +the matplotlib code ``ax`` represents the Plot Axes i.e. ``fig, ax = plt.subplots()`` after importing ``import matplotlib.pyplot as plt``. For more details see the `matplotlib User's Guide `_. For Chaco code, ``p`` is the :class:`~.Plot` instance. ``x`` and ``y`` are the -data to be plotted. In chaco, this data needs to be wrapped in a +data to be plotted. In Chaco, this data needs to be wrapped in a ``PlotData`` object. For example, :: @@ -25,7 +25,7 @@ data to be plotted. In chaco, this data needs to be wrapped in a x = np.linspace(-2*pi, 2*pi, 100) y = sin(x) - # chaco only + # Chaco only pd = ArrayPlotData() pd.set_data("x", x) pd.set_data("y", y) @@ -33,7 +33,7 @@ data to be plotted. In chaco, this data needs to be wrapped in a Note that in the matplotlib column, ``x`` and ``y`` represent the data, but ``'x'`` and ``'y'``, such as in the "X grid" and "Y Grid" rows are simply -options for the ``axis`` argument. In chaco ``'x'`` and ``'y'`` are the names +options for the ``axis`` argument. In Chaco ``'x'`` and ``'y'`` are the names the ``PlotData`` object associates with numpy arrays ``x`` and ``y``. .. list-table:: Matplotlib To Chaco Cheatsheet From 91f47c6b8937d51de7e83367a6165797a17ccd57 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Wed, 5 May 2021 09:58:54 -0500 Subject: [PATCH 11/12] double backticks and dont capialze low/high --- .../user_manual/matplotlib_to_chaco.rst | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index d052570d6..abbc33c3e 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -44,47 +44,47 @@ the ``PlotData`` object associates with numpy arrays ``x`` and ``y``. - Matplotlib - Chaco * - Plot lines - - `ax.plot(x, y)` - - `p.plot(('x', 'y'))` + - ``ax.plot(x, y)`` + - ``p.plot(('x', 'y'))`` * - x label - - `ax.set_xlabel('Time')` - - `p.x_axis.title = 'Time'` + - ``ax.set_xlabel('Time')`` + - ``p.x_axis.title = 'Time'`` * - y label - - `ax.set_ylabel('Value')` - - `p.y_axis.title = 'Value'` + - ``ax.set_ylabel('Value')`` + - ``p.y_axis.title = 'Value'`` * - Title - - `ax.set_title(title)` - - `p.title = title` + - ``ax.set_title(title)`` + - ``p.title = title`` * - X limits - - `ax.set_xlim((low, high))` - - `p.index_range.low_setting = LOW` `p.index_range.high_setting = HIGH` + - ``ax.set_xlim((low, high))`` + - ``p.index_range.low_setting = low`` ``p.index_range.high_setting = high`` * - Y limits - - `ax.set_ylim((low, high))` - - `p.value_range.low_setting = LOW` `p.value_range.high_setting = HIGH` + - ``ax.set_ylim((low, high))`` + - ``p.value_range.low_setting = low`` ``p.value_range.high_setting = high`` * - Label lines for legend - - `ax.plot(…, label=label)` - - `p.plot(…, name=name)` + - ``ax.plot(…, label=label)`` + - ``p.plot(…, name=name)`` * - Add legend - - `ax.legend()` - - `p.legend.visible = True` + - ``ax.legend()`` + - ``p.legend.visible = True`` * - Legend position - - `ax.legend(loc='lower left')` - - `p.legend_alignment = 'll'` + - ``ax.legend(loc='lower left')`` + - ``p.legend_alignment = 'll'`` * - Background color - - `ax.set_facecolor('white')` - - `p.bgcolor = 'white'` + - ``ax.set_facecolor('white')`` + - ``p.bgcolor = 'white'`` * - Show spines - - `ax.spines.set_color('black')` - - `p.border_visible = True` + - ``ax.spines.set_color('black')`` + - ``p.border_visible = True`` * - Line width - - `ax.plot(linewidth=lw)` - - `p.line_width = 1.1` or `p.plot(…, linewidth=lw)` + - ``ax.plot(linewidth=lw)`` + - ``p.line_width = 1.1`` or ``p.plot(…, linewidth=lw)`` * - X grid - - `ax.grid(axis='x')` - - `p.x_axis.visible = True` + - ``ax.grid(axis='x')`` + - ``p.x_axis.visible = True`` * - Y grid - - `ax.grid(axis='y')` - - `p.y_axis.visible = True` + - ``ax.grid(axis='y')`` + - ``p.y_axis.visible = True`` * - Second y ticks - - `ax.yaxis.set_label_position('right')` `ax.yaxis.tick_right()` - - `p.y_axis.orientation = "right"` + - ``ax.yaxis.set_label_position('right')`` ``ax.yaxis.tick_right()`` + - ``p.y_axis.orientation = "right"`` From 41a61643e6ee9d4deebc40cd9c65e4fb3a4c840e Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Wed, 5 May 2021 10:57:10 -0500 Subject: [PATCH 12/12] use np.pi not pi --- docs/source/user_manual/matplotlib_to_chaco.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/user_manual/matplotlib_to_chaco.rst b/docs/source/user_manual/matplotlib_to_chaco.rst index abbc33c3e..5ca442ae9 100644 --- a/docs/source/user_manual/matplotlib_to_chaco.rst +++ b/docs/source/user_manual/matplotlib_to_chaco.rst @@ -22,7 +22,7 @@ data to be plotted. In Chaco, this data needs to be wrapped in a :: import numpy as np - x = np.linspace(-2*pi, 2*pi, 100) + x = np.linspace(-2*np.pi, 2*np.pi, 100) y = sin(x) # Chaco only