-
Notifications
You must be signed in to change notification settings - Fork 98
Matplotlib to chaco cheatsheet in docs #723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8d7e003
start of matplotlib_to_chaco
aaronayres35 6c7e0ef
fill table and explain ax / p
aaronayres35 8e6a8d3
typo
aaronayres35 1c58a7a
remove extra space
aaronayres35 5d75906
Update docs/source/user_manual/matplotlib_to_chaco.rst
aaronayres35 e91f818
suggestions from code review
aaronayres35 49ab111
use list-table
aaronayres35 0742255
typos / grammar
aaronayres35 16512d1
Update docs/source/user_manual/matplotlib_to_chaco.rst
aaronayres35 84e3005
Apply suggestions from code review
aaronayres35 91f47c6
double backticks and dont capialze low/high
aaronayres35 41a6164
use np.pi not pi
aaronayres35 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,3 +26,4 @@ User Guide | |
| common_patterns.rst | ||
| how_do_i.rst | ||
| faq.rst | ||
| matplotlib_to_chaco.rst | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| .. _matplotlib2chaco: | ||
|
|
||
| ############################## | ||
| Matplotlib to Chaco Cheatsheet | ||
| ############################## | ||
| As mentioned in the :ref:`Chaco Tutorial <tutorial>`, | ||
| `matplotlib <https://matplotlib.org/>`_ 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 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`` 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 <https://matplotlib.org/stable/users/index.html>`_. | ||
| 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 | ||
| ``PlotData`` object. For example, | ||
|
|
||
| :: | ||
|
|
||
| import numpy as np | ||
| x = np.linspace(-2*np.pi, 2*np.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`` 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``. | ||
|
|
||
| .. 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"`` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's something new i learnt today!