diff --git a/docs/FAQ/Makefile b/docs/FAQ/Makefile new file mode 100644 index 000000000..ac8769f38 --- /dev/null +++ b/docs/FAQ/Makefile @@ -0,0 +1,153 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ChacoFAQ.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ChacoFAQ.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/ChacoFAQ" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ChacoFAQ" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." diff --git a/docs/FAQ/make.bat b/docs/FAQ/make.bat new file mode 100644 index 000000000..44aba0c74 --- /dev/null +++ b/docs/FAQ/make.bat @@ -0,0 +1,190 @@ +@ECHO OFF + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set BUILDDIR=build +set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source +set I18NSPHINXOPTS=%SPHINXOPTS% source +if NOT "%PAPER%" == "" ( + set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% + set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% +) + +if "%1" == "" goto help + +if "%1" == "help" ( + :help + echo.Please use `make ^` where ^ is one of + echo. html to make standalone HTML files + echo. dirhtml to make HTML files named index.html in directories + echo. singlehtml to make a single large HTML file + echo. pickle to make pickle files + echo. json to make JSON files + echo. htmlhelp to make HTML files and a HTML help project + echo. qthelp to make HTML files and a qthelp project + echo. devhelp to make HTML files and a Devhelp project + echo. epub to make an epub + echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter + echo. text to make text files + echo. man to make manual pages + echo. texinfo to make Texinfo files + echo. gettext to make PO message catalogs + echo. changes to make an overview over all changed/added/deprecated items + echo. linkcheck to check all external links for integrity + echo. doctest to run all doctests embedded in the documentation if enabled + goto end +) + +if "%1" == "clean" ( + for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i + del /q /s %BUILDDIR%\* + goto end +) + +if "%1" == "html" ( + %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/html. + goto end +) + +if "%1" == "dirhtml" ( + %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. + goto end +) + +if "%1" == "singlehtml" ( + %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. + goto end +) + +if "%1" == "pickle" ( + %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the pickle files. + goto end +) + +if "%1" == "json" ( + %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can process the JSON files. + goto end +) + +if "%1" == "htmlhelp" ( + %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run HTML Help Workshop with the ^ +.hhp project file in %BUILDDIR%/htmlhelp. + goto end +) + +if "%1" == "qthelp" ( + %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; now you can run "qcollectiongenerator" with the ^ +.qhcp project file in %BUILDDIR%/qthelp, like this: + echo.^> qcollectiongenerator %BUILDDIR%\qthelp\ChacoFAQ.qhcp + echo.To view the help file: + echo.^> assistant -collectionFile %BUILDDIR%\qthelp\ChacoFAQ.ghc + goto end +) + +if "%1" == "devhelp" ( + %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. + goto end +) + +if "%1" == "epub" ( + %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The epub file is in %BUILDDIR%/epub. + goto end +) + +if "%1" == "latex" ( + %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex + if errorlevel 1 exit /b 1 + echo. + echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. + goto end +) + +if "%1" == "text" ( + %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The text files are in %BUILDDIR%/text. + goto end +) + +if "%1" == "man" ( + %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The manual pages are in %BUILDDIR%/man. + goto end +) + +if "%1" == "texinfo" ( + %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. + goto end +) + +if "%1" == "gettext" ( + %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale + if errorlevel 1 exit /b 1 + echo. + echo.Build finished. The message catalogs are in %BUILDDIR%/locale. + goto end +) + +if "%1" == "changes" ( + %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes + if errorlevel 1 exit /b 1 + echo. + echo.The overview file is in %BUILDDIR%/changes. + goto end +) + +if "%1" == "linkcheck" ( + %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck + if errorlevel 1 exit /b 1 + echo. + echo.Link check complete; look for any errors in the above output ^ +or in %BUILDDIR%/linkcheck/output.txt. + goto end +) + +if "%1" == "doctest" ( + %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest + if errorlevel 1 exit /b 1 + echo. + echo.Testing of doctests in the sources finished, look at the ^ +results in %BUILDDIR%/doctest/output.txt. + goto end +) + +:end diff --git a/docs/FAQ/source/cheatSheet/cheatSheet.rst b/docs/FAQ/source/cheatSheet/cheatSheet.rst new file mode 100644 index 000000000..e99d006ee --- /dev/null +++ b/docs/FAQ/source/cheatSheet/cheatSheet.rst @@ -0,0 +1,461 @@ +Chaco Plot Cheat Sheet +====================== + +.. highlight:: python + :linenothreshold: 5 + +.. index:: Cheat Sheet + +Data and Data Descriptors +------------------------- + +Adding data for a plot:: + + myTADP = ArrayPlotData() + myTADP.set_data( [Variable Name - String],[Data - Array, List, Tuple] ) + + # data must evaluate to a list, tuple or numpy array + + # Example + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + +Masking Data +------------ + +You can replace any data with None to not plot the data. Works for the index +and value entries. + +Setting the mask values in the ArrayDataSource to False does not filter the +plotted data based upon the True/False states of the particular mask value. + +Padding +------- + +.. todo:: clarify these snippets + +The padding attributes represent the number of pixels set aside around +a plot. The fundamental attributes are + + [padding_left, padding_right, padding_top, padding_bottom] + +Retrive the padding using:: + + myFirstPlot.myTP.padding + [50, 50, 50, 50] + # returns [padding_left, padding_right, padding_top, padding_bottom] + +You can also set equal padding by:: + + myFirstPlot.myTP.padding = 25 + # results in padding of [25,25,25,25] + [50, 50, 50, 50] + +.. index:: + pair: Color; Alias + +Color Aliases +------------- + +From enable/colors.py +:: + + transparent_color = (0.0, 0.0, 0.0, 0.0) + + color_table = { + "aliceblue": (0.941, 0.973, 1.000, 1.0), + "antiquewhite": (0.980, 0.922, 0.843, 1.0), + "aqua": (0.000, 1.000, 1.000, 1.0), + "aquamarine": (0.498, 1.000, 0.831, 1.0), + "azure": (0.941, 1.000, 1.000, 1.0), + "beige": (0.961, 0.961, 0.863, 1.0), + "bisque": (1.000, 0.894, 0.769, 1.0), + "black": (0.000, 0.000, 0.000, 1.0), + "blanchedalmond": (1.000, 0.922, 0.804, 1.0), + "blue": (0.000, 0.000, 1.000, 1.0), + "blueviolet": (0.541, 0.169, 0.886, 1.0), + "brown": (0.647, 0.165, 0.165, 1.0), + "burlywood": (0.871, 0.722, 0.529, 1.0), + "cadetblue": (0.373, 0.620, 0.627, 1.0), + "chartreuse": (0.498, 1.000, 0.000, 1.0), + "chocolate": (0.824, 0.412, 0.118, 1.0), + "coral": (1.000, 0.498, 0.314, 1.0), + "cornflowerblue": (0.392, 0.584, 0.929, 1.0), + "cornsilk": (1.000, 0.973, 0.863, 1.0), + "crimson": (0.863, 0.078, 0.235, 1.0), + "cyan": (0.000, 1.000, 1.000, 1.0), + "darkblue": (0.000, 0.000, 0.545, 1.0), + "darkcyan": (0.000, 0.545, 0.545, 1.0), + "darkgoldenrod": (0.722, 0.525, 0.043, 1.0), + "darkgray": (0.663, 0.663, 0.663, 1.0), + "darkgreen": (0.000, 0.392, 0.000, 1.0), + "darkgrey": (0.663, 0.663, 0.663, 1.0), + "darkkhaki": (0.741, 0.718, 0.420, 1.0), + "darkmagenta": (0.545, 0.000, 0.545, 1.0), + "darkolivegreen": (0.333, 0.420, 0.184, 1.0), + "darkorange": (1.000, 0.549, 0.000, 1.0), + "darkorchid": (0.600, 0.196, 0.800, 1.0), + "darkred": (0.545, 0.000, 0.000, 1.0), + "darksalmon": (0.914, 0.588, 0.478, 1.0), + "darkseagreen": (0.561, 0.737, 0.561, 1.0), + "darkslateblue": (0.282, 0.239, 0.545, 1.0), + "darkslategray": (0.184, 0.310, 0.310, 1.0), + "darkslategrey": (0.184, 0.310, 0.310, 1.0), + "darkturquoise": (0.000, 0.808, 0.820, 1.0), + "darkviolet": (0.580, 0.000, 0.827, 1.0), + "deeppink": (1.000, 0.078, 0.576, 1.0), + "deepskyblue": (0.000, 0.749, 1.000, 1.0), + "dimgray": (0.412, 0.412, 0.412, 1.0), + "dimgrey": (0.412, 0.412, 0.412, 1.0), + "dodgerblue": (0.118, 0.565, 1.000, 1.0), + "firebrick": (0.698, 0.133, 0.133, 1.0), + "floralwhite": (1.000, 0.980, 0.941, 1.0), + "forestgreen": (0.133, 0.545, 0.133, 1.0), + "fuchsia": (1.000, 0.000, 1.000, 1.0), + "gainsboro": (0.863, 0.863, 0.863, 1.0), + "ghostwhite": (0.973, 0.973, 1.000, 1.0), + "gold": (1.000, 0.843, 0.000, 1.0), + "goldenrod": (0.855, 0.647, 0.125, 1.0), + "gray": (0.502, 0.502, 0.502, 1.0), + "green": (0.000, 0.502, 0.000, 1.0), + "greenyellow": (0.678, 1.000, 0.184, 1.0), + "grey": (0.502, 0.502, 0.502, 1.0), + "honeydew": (0.941, 1.000, 0.941, 1.0), + "hotpink": (1.000, 0.412, 0.706, 1.0), + "indianred": (0.804, 0.361, 0.361, 1.0), + "indigo": (0.294, 0.000, 0.510, 1.0), + "ivory": (1.000, 1.000, 0.941, 1.0), + "khaki": (0.941, 0.902, 0.549, 1.0), + "lavender": (0.902, 0.902, 0.980, 1.0), + "lavenderblush": (1.000, 0.941, 0.961, 1.0), + "lawngreen": (0.486, 0.988, 0.000, 1.0), + "lemonchiffon": (1.000, 0.980, 0.804, 1.0), + "lightblue": (0.678, 0.847, 0.902, 1.0), + "lightcoral": (0.941, 0.502, 0.502, 1.0), + "lightcyan": (0.878, 1.000, 1.000, 1.0), + "lightgoldenrodyellow":(0.980, 0.980, 0.824, 1.0), + "lightgray": (0.827, 0.827, 0.827, 1.0), + "lightgreen": (0.565, 0.933, 0.565, 1.0), + "lightgrey": (0.827, 0.827, 0.827, 1.0), + "lightpink": (1.000, 0.714, 0.757, 1.0), + "lightsalmon": (1.000, 0.627, 0.478, 1.0), + "lightseagreen": (0.125, 0.698, 0.667, 1.0), + "lightskyblue": (0.529, 0.808, 0.980, 1.0), + "lightslategray": (0.467, 0.533, 0.600, 1.0), + "lightslategrey": (0.467, 0.533, 0.600, 1.0), + "lightsteelblue": (0.690, 0.769, 0.871, 1.0), + "lightyellow": (1.000, 1.000, 0.878, 1.0), + "lime": (0.000, 1.000, 0.000, 1.0), + "limegreen": (0.196, 0.804, 0.196, 1.0), + "linen": (0.980, 0.941, 0.902, 1.0), + "magenta": (1.000, 0.000, 1.000, 1.0), + "maroon": (0.502, 0.000, 0.000, 1.0), + "mediumaquamarine": (0.400, 0.804, 0.667, 1.0), + "mediumblue": (0.000, 0.000, 0.804, 1.0), + "mediumorchid": (0.729, 0.333, 0.827, 1.0), + "mediumpurple": (0.576, 0.439, 0.859, 1.0), + "mediumseagreen": (0.235, 0.702, 0.443, 1.0), + "mediumslateblue": (0.482, 0.408, 0.933, 1.0), + "mediumspringgreen": (0.000, 0.980, 0.604, 1.0), + "mediumturquoise": (0.282, 0.820, 0.800, 1.0), + "mediumvioletred": (0.780, 0.082, 0.522, 1.0), + "midnightblue": (0.098, 0.098, 0.439, 1.0), + "mintcream": (0.961, 1.000, 0.980, 1.0), + "mistyrose": (1.000, 0.894, 0.882, 1.0), + "moccasin": (1.000, 0.894, 0.710, 1.0), + "navajowhite": (1.000, 0.871, 0.678, 1.0), + "navy": (0.000, 0.000, 0.502, 1.0), + "oldlace": (0.992, 0.961, 0.902, 1.0), + "olive": (0.502, 0.502, 0.000, 1.0), + "olivedrab": (0.420, 0.557, 0.137, 1.0), + "orange": (1.000, 0.647, 0.000, 1.0), + "orangered": (1.000, 0.271, 0.000, 1.0), + "orchid": (0.855, 0.439, 0.839, 1.0), + "palegoldenrod": (0.933, 0.910, 0.667, 1.0), + "palegreen": (0.596, 0.984, 0.596, 1.0), + "paleturquoise": (0.686, 0.933, 0.933, 1.0), + "palevioletred": (0.859, 0.439, 0.576, 1.0), + "papayawhip": (1.000, 0.937, 0.835, 1.0), + "peachpuff": (1.000, 0.855, 0.725, 1.0), + "peru": (0.804, 0.522, 0.247, 1.0), + "pink": (1.000, 0.753, 0.796, 1.0), + "plum": (0.867, 0.627, 0.867, 1.0), + "powderblue": (0.690, 0.878, 0.902, 1.0), + "purple": (0.502, 0.000, 0.502, 1.0), + "red": (1.000, 0.000, 0.000, 1.0), + "rosybrown": (0.737, 0.561, 0.561, 1.0), + "royalblue": (0.255, 0.412, 0.882, 1.0), + "saddlebrown": (0.545, 0.271, 0.075, 1.0), + "salmon": (0.980, 0.502, 0.447, 1.0), + "sandybrown": (0.957, 0.643, 0.376, 1.0), + "seagreen": (0.180, 0.545, 0.341, 1.0), + "seashell": (1.000, 0.961, 0.933, 1.0), + "sienna": (0.627, 0.322, 0.176, 1.0), + "silver": (0.753, 0.753, 0.753, 1.0), + "skyblue": (0.529, 0.808, 0.922, 1.0), + "slateblue": (0.416, 0.353, 0.804, 1.0), + "slategray": (0.439, 0.502, 0.565, 1.0), + "slategrey": (0.439, 0.502, 0.565, 1.0), + "snow": (1.000, 0.980, 0.980, 1.0), + "springgreen": (0.000, 1.000, 0.498, 1.0), + "steelblue": (0.275, 0.510, 0.706, 1.0), + "tan": (0.824, 0.706, 0.549, 1.0), + "teal": (0.000, 0.502, 0.502, 1.0), + "thistle": (0.847, 0.749, 0.847, 1.0), + "tomato": (1.000, 0.388, 0.278, 1.0), + "turquoise": (0.251, 0.878, 0.816, 1.0), + "violet": (0.933, 0.510, 0.933, 1.0), + "wheat": (0.961, 0.871, 0.702, 1.0), + "white": (1.000, 1.000, 1.000, 1.0), + "whitesmoke": (0.961, 0.961, 0.961, 1.0), + "yellow": (1.000, 1.000, 0.000, 1.0), + "yellowgreen": (0.604, 0.804, 0.196, 1.0), + + # Several aliases for transparent + "clear": transparent_color, + "transparent": transparent_color, + "none": transparent_color, + + # Placeholders for system- and toolkit-specific UI colors; the + # toolkit-dependent code below will fill these with the appropriate + # values. These hardcoded defaults are for the Windows Classic + # theme. + "sys_window" : (0.83137, 0.81569, 0.78431, 1.0), + } + +.. index:: + pair: Styles; Line + pair: Alias; Line Styles + single: Grid; Line Styles + +Line Styles +----------- + +From enable/enable_traits.py:: + + __line_style_trait_values = { + 'solid': None, + 'dot dash': array( [ 3.0, 5.0, 9.0, 5.0 ] ), + 'dash': array( [ 6.0, 6.0 ] ), + 'dot': array( [ 2.0, 2.0 ] ), + 'long dash': array( [ 9.0, 5.0 ] ) + } + +.. index:: + pair: Styles; Cursor + pair: Alias; Cursor + single: Cursor; Styles + +Cursor Styles +------------- + +From enable/enable_traits.py:: + + # Valid pointer shape names: + pointer_shapes = [ + 'arrow', 'right arrow', 'blank', 'bullseye', 'char', 'cross', 'hand', + 'ibeam', 'left button', 'magnifier', 'middle button', 'no entry', + 'paint brush', 'pencil', 'point left', 'point right', 'question arrow', + 'right button', 'size top', 'size bottom', 'size left', 'size right', + 'size top right', 'size bottom left', 'size top left', 'size bottom right', + 'sizing', 'spray can', 'wait', 'watch', 'arrow wait' + ] + +.. index: + pair: Fonts; Alias + +Fonts +----- + +From kiva_font_traits.py:: + + font = KivaFont("modern 10 bold") + modern + arial + courier + + font size + + font attribute = bold italic underline + + # Mapping of strings to valid Kiva font families: + font_families = { + 'default': kc.DEFAULT, + 'decorative': kc.DECORATIVE, + 'roman': kc.ROMAN, + 'script': kc.SCRIPT, + 'swiss': kc.SWISS, + 'modern': kc.MODERN + } + + # Mapping of strings to Kiva font styles: + font_styles = { + 'italic': kc.ITALIC + } + + # Mapping of strings to Kiva font weights: + font_weights = { + 'bold': kc.BOLD + } + + default_face = { + kc.SWISS: "Arial", + kc.ROMAN: "Times", + kc.MODERN: "Courier", + kc.SCRIPT: "Zapfino", + kc.DECORATIVE: "Zapfino", # need better choice for this + } + + # Mapping of strings to valid Kiva font families: + font_families = { + 'default': kc.DEFAULT, + 'decorative': kc.DECORATIVE, + 'roman': kc.ROMAN, + 'script': kc.SCRIPT, + 'swiss': kc.SWISS, + 'modern': kc.MODERN + } + + # Mapping of strings to Kiva font styles: + font_styles = { + 'italic': kc.ITALIC + } + + # Mapping of strings to Kiva font weights: + font_weights = { + 'bold': kc.BOLD + } + + default_face = { + kc.SWISS: "Arial", + kc.ROMAN: "Times", + kc.MODERN: "Courier", + kc.SCRIPT: "Zapfino", + kc.DECORATIVE: "Zapfino", # need better choice for this + } + + def info ( self ): + return ( "a string describing a font (e.g. '12 pt bold italic " + "swiss family Arial' or 'default 12')" ) + +.. index: + pair: Colormap; Alias + +Colormaps +--------- +:: + + # Make the convenient list of all the function names as well as a dictionary + # of name->function mappings. These are useful for UI editors. + + Found in chaco\default_colormaps.py + + color_map_functions = [ + jet, + autumn, + bone, + cool, + copper, + flag, + gray, + yarg, + hot, + hsv, + pink, + prism, + spring, + summer, + winter, + cw1_004, + cw1_005, + cw1_006, + cw1_028, + gmt_drywet, + Spectral, + RdBu, + RdPu, + YlGnBu, + RdYlBu, + GnBu, + RdYlGn, + PuBu, + BuGn, + Greens, + PRGn, + BuPu, + OrRd, + Oranges, + PiYG, + YlGn, + BrBG, + Reds, + RdGy, + PuRd, + Blues, + Greys, + YlOrRd, + YlOrBr, + Purples, + PuOr, + PuBuGn, + gist_earth, + gist_gray, + gist_heat, + gist_ncar, + gist_rainbow, + gist_stern, + gist_yarg, + ] + +from default_colors.py:: + + """List of nice color palettes for Chaco""" + + # This is a palette of 10 nice colors to use for mapping/discrete + # color differentiation. From ColorBrewer. + cbrewer = [ + (0.65098039, 0.80784314, 0.89019608, 1.0), + (0.12156863, 0.47058824, 0.70588235, 1.0), + (0.69803922, 0.8745098 , 0.54117647, 1.0), + (0.2 , 0.62745098, 0.17254902, 1.0), + (0.98431373, 0.60392157, 0.6 , 1.0), + (0.89019608, 0.10196078, 0.10980392, 1.0), + (0.99215686, 0.74901961, 0.43529412, 1.0), + (1. , 0.49803922, 0. , 1.0), + (0.79215686, 0.69803922, 0.83921569, 1.0), + (0.41568627, 0.23921569, 0.60392157, 1.0), + ] + + palette11 = [ + (0.725490, 0.329412, 0.615686, 1.0), + (0.121569, 0.313725, 0.552941, 1.0), + (0.376471, 0.525490, 0.082353, 1.0), + (0.435294, 0.380392, 0.572549, 1.0), + (0.988235, 0.400000, 0.600000, 1.0), + (0.133333, 0.588235, 0.976471, 1.0), + (0.992157, 0.600000, 0.400000, 1.0), + (0.611765, 0.200000, 0.380392, 1.0), + (0.388235, 0.647059, 0.537255, 1.0), + (0.545098, 0.686275, 0.874510, 1.0), + (0.623529, 0.501961, 0.862745, 1.0), + ] + + palette14 = [ + (0.286275, 0.235294, 0.545098, 1.0), + (0.976471, 0.709804, 0.313725, 1.0), + (0.850980, 0.094118, 0.521569, 1.0), + (0.431373, 0.662745, 0.431373, 1.0), + (0.803922, 0.345098, 0.345098, 1.0), + (0.015686, 0.749020, 0.403922, 1.0), + (0.694118, 0.686275, 0.580392, 1.0), + (0.376471, 0.298039, 0.788235, 1.0), + (0.992157, 0.396078, 0.011765, 1.0), + (0.298039, 0.776471, 0.615686, 1.0), + (0.988235, 0.407843, 0.686275, 1.0), + (0.000000, 0.600000, 0.984314, 1.0), + (0.470588, 0.917647, 0.478431, 1.0), + (0.627451, 0.250980, 0.815686, 1.0), + ] + + PALETTES = [cbrewer, palette11, palette14] diff --git a/docs/FAQ/source/colorbar/colorbar.rst b/docs/FAQ/source/colorbar/colorbar.rst new file mode 100644 index 000000000..c5cb3389d --- /dev/null +++ b/docs/FAQ/source/colorbar/colorbar.rst @@ -0,0 +1,276 @@ +Colorbars and Image Plots +========================= + +.. highlight:: python + :linenothreshold: 5 + +.. index:: + pair: Plot; Image + +Chaco Image Plot +---------------- + +Let's build a simple Chaco image plot and add a colorbar to it. First, we +build an image plot:: + + ## ex_chaco_colorbar_01.py + + # standard imports + import os, inspect + + # numpy imports + from numpy import sin, exp, linspace, meshgrid, pi + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import ArrayPlotData, jet, Plot + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot + myTP = Plot( myAPD ) + + # add the image plot to this plot object + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = jet, + ) + + # add the title and padding around the plot + myTP.title = "2D sin(x)/x" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X Phase (rad)" + myTP.y_axis.title = "Y Phase (rad)" + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + +The resulting plot is + +.. figure:: ex_chaco_colorbar_01.png + :scale: 100 % + :align: center + :alt: A simple Chaco image plot without a colorbar + + A simple Chaco image plot without a colorbar + +We add a colorbar to this plot by generating a ColorBar instance and attaching +it to the plot. The ColorBar object has a PlotAxis object, named ``_axis``, that +handles the characteristics of the Colarbar labels. + +If we like, we can also generate a title for the ColorBar using PlotLabel +instance. We then attach the PlotLabel and ColorBar together. The code for the +colorbar'ed image plot (with some introspection added) is:: + + ## ex_chaco_colorbar_02.py + + # standard imports + import os, inspect + + # numpy imports + from numpy import sin, exp, linspace, meshgrid, pi + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import ArrayPlotData, jet, Plot, ColorBar + from chaco.api import LinearMapper, HPlotContainer, PlotLabel + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + + # Create the plot + myTP = Plot( myAPD ) + + # add the image plot to this plot object + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = jet, + ) + + # add the title and padding around the plot + myTP.title = "2D sin(x)/x" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X Phase (rad)" + myTP.y_axis.title = "Y Phase (rad)" + + # generate a ColorBar instance + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + color_mapper = myTP.color_mapper, + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # set up the ColorBar grid and axes + myTCB.grid_visible = True + + myTCB._axis.axis_line_color = 'black' + myTCB._axis.axis_line_style = 'solid' + myTCB._axis.axis_line_visible = True + myTCB._axis.axis_line_weight = 1.0 + + myTCB._axis.bgcolor = 'transparent' + myTCB._axis.border_color ='black' + myTCB._axis.border_dash = 'solid' + myTCB._axis.border_visible = False + myTCB._axis.border_width = 1 + + myTCB._axis.orientation = 'left' # 'left' or 'right' + + myTCB._axis.resizable = 'hv' + myTCB._axis.small_haxis_style = False + myTCB._axis.tick_color = 'black' + myTCB._axis.tick_in = 5 + myTCB._axis.tick_interval = 'auto' + myTCB._axis.tick_label_alignment = 'edge' + myTCB._axis.tick_label_color = 'black' + myTCB._axis.tick_label_font = 'Arial 12' + myTCB._axis.tick_label_margin = 2 + myTCB._axis.tick_label_offset = 8.0 + myTCB._axis.tick_label_position = 'outside' + myTCB._axis.tick_label_rotate_angle = 0 + myTCB._axis.tick_out = 5 + myTCB._axis.tick_visible = True + myTCB._axis.tick_weight = 1.0 + myTCB._axis.title = 'Value of Z' + myTCB._axis.title_angle = 90.0 + myTCB._axis.title_color = 'black' + myTCB._axis.title_font = 'Arial 14' + myTCB._axis.title_spacing = 'auto' + + # build a plot title for the ColorBar out of a PlotLabel instance + myTPL = PlotLabel() + + # tell the PlotLabel that its parent component is the ColorBar and tell the + # ColorBar that one of its overlays is the PlotLabel + myTPL.component = myTCB + myTCB.overlays.append( myTPL ) + + # Text, fonts, etc. + myTPL.text = "Z Value" + myTPL.font = "Arial 16 bold" + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + myHPC.bgcolor = "lightgray" + + # set up the view for the graphic and colorbar + traits_view = View( + Group( + Item( 'myHPC', + editor = ComponentEditor( size = windowSize ), + show_label = False + ), + orientation = "vertical" + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + # build the object, and show the window + tp = TraitedPlot() + tp.configure_traits() + + # examine the ColorBar object + print( type(tp.myTCB) ) + + membersList = inspect.getmembers( tp.myTCB ) + publicList = [thisItem for thisItem in membersList if thisItem[0][0] != '_'] + print( publicList ) + + tp.myTCB.print_traits() + + # look at the _axis trait of the ColorBar + print( type(tp.myTCB._axis) ) + + membersList = inspect.getmembers( tp.myTCB._axis ) + publicList = [thisItem for thisItem in membersList if thisItem[0][0] != '_'] + print( publicList ) + + tp.myTCB._axis.print_traits() + +The resulting plot is + +.. figure:: ex_chaco_colorbar_02.png + :scale: 100 % + :align: center + :alt: A single TraitsUI window + + A single TraitsUI window diff --git a/docs/FAQ/source/colorbar/ex_chaco_colorbar_01.png b/docs/FAQ/source/colorbar/ex_chaco_colorbar_01.png new file mode 100644 index 000000000..400fd2385 Binary files /dev/null and b/docs/FAQ/source/colorbar/ex_chaco_colorbar_01.png differ diff --git a/docs/FAQ/source/colorbar/ex_chaco_colorbar_01.py b/docs/FAQ/source/colorbar/ex_chaco_colorbar_01.py new file mode 100644 index 000000000..799d1ed91 --- /dev/null +++ b/docs/FAQ/source/colorbar/ex_chaco_colorbar_01.py @@ -0,0 +1,73 @@ +## ex_chaco_colorbar_01.py + +# standard imports +import os, inspect + +# numpy imports +from numpy import sin, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import ArrayPlotData, jet, Plot + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot + myTP = Plot( myAPD ) + + # add the image plot to this plot object + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = jet, + ) + + # add the title and padding around the plot + myTP.title = "2D sin(x)/x" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X Phase (rad)" + myTP.y_axis.title = "Y Phase (rad)" + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + diff --git a/docs/FAQ/source/colorbar/ex_chaco_colorbar_02.png b/docs/FAQ/source/colorbar/ex_chaco_colorbar_02.png new file mode 100644 index 000000000..f716b1db6 Binary files /dev/null and b/docs/FAQ/source/colorbar/ex_chaco_colorbar_02.png differ diff --git a/docs/FAQ/source/colorbar/ex_chaco_colorbar_02.py b/docs/FAQ/source/colorbar/ex_chaco_colorbar_02.py new file mode 100644 index 000000000..98c888019 --- /dev/null +++ b/docs/FAQ/source/colorbar/ex_chaco_colorbar_02.py @@ -0,0 +1,162 @@ +## ex_chaco_colorbar_02.py + +# standard imports +import os, inspect + +# numpy imports +from numpy import sin, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import ArrayPlotData, jet, Plot, ColorBar +from chaco.api import LinearMapper, HPlotContainer, PlotLabel + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + + # Create the plot + myTP = Plot( myAPD ) + + # add the image plot to this plot object + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = jet, + ) + + # add the title and padding around the plot + myTP.title = "2D sin(x)/x" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X Phase (rad)" + myTP.y_axis.title = "Y Phase (rad)" + + # generate a ColorBar instance + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + color_mapper = myTP.color_mapper, + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # set up the ColorBar grid and axes + myTCB.grid_visible = True + + myTCB._axis.axis_line_color = 'black' + myTCB._axis.axis_line_style = 'solid' + myTCB._axis.axis_line_visible = True + myTCB._axis.axis_line_weight = 1.0 + + myTCB._axis.bgcolor = 'transparent' + myTCB._axis.border_color ='black' + myTCB._axis.border_dash = 'solid' + myTCB._axis.border_visible = False + myTCB._axis.border_width = 1 + + myTCB._axis.orientation = 'left' # 'left' or 'right' + + myTCB._axis.resizable = 'hv' + myTCB._axis.small_haxis_style = False + myTCB._axis.tick_color = 'black' + myTCB._axis.tick_in = 5 + myTCB._axis.tick_interval = 'auto' + myTCB._axis.tick_label_alignment = 'edge' + myTCB._axis.tick_label_color = 'black' + myTCB._axis.tick_label_font = 'Arial 12' + myTCB._axis.tick_label_margin = 2 + myTCB._axis.tick_label_offset = 8.0 + myTCB._axis.tick_label_position = 'outside' + myTCB._axis.tick_label_rotate_angle = 0 + myTCB._axis.tick_out = 5 + myTCB._axis.tick_visible = True + myTCB._axis.tick_weight = 1.0 + myTCB._axis.title = 'Value of Z' + myTCB._axis.title_angle = 90.0 + myTCB._axis.title_color = 'black' + myTCB._axis.title_font = 'Arial 14' + myTCB._axis.title_spacing = 'auto' + + # build a plot title for the ColorBar out of a PlotLabel instance + myTPL = PlotLabel() + + # tell the PlotLabel that its parent component is the ColorBar and tell the + # ColorBar that one of its overlays is the PlotLabel + myTPL.component = myTCB + myTCB.overlays.append( myTPL ) + + # Text, fonts, etc. + myTPL.text = "Z Value" + myTPL.font = "Arial 16 bold" + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + myHPC.bgcolor = "lightgray" + + # set up the view for the graphic and colorbar + traits_view = View( + Group( + Item( 'myHPC', + editor = ComponentEditor( size = windowSize ), + show_label = False + ), + orientation = "vertical" + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + # build the object, and show the window + tp = TraitedPlot() + tp.configure_traits() + + # examine the ColorBar object + print( type(tp.myTCB) ) + + membersList = inspect.getmembers( tp.myTCB ) + publicList = [thisItem for thisItem in membersList if thisItem[0][0] != '_'] + print( publicList ) + + tp.myTCB.print_traits() + + # look at the _axis trait of the ColorBar + print( type(tp.myTCB._axis) ) + + membersList = inspect.getmembers( tp.myTCB._axis ) + publicList = [thisItem for thisItem in membersList if thisItem[0][0] != '_'] + print( publicList ) + + tp.myTCB._axis.print_traits() diff --git a/docs/FAQ/source/colorbar/ex_chaco_colorbar_03.py b/docs/FAQ/source/colorbar/ex_chaco_colorbar_03.py new file mode 100644 index 000000000..9f9279f7c --- /dev/null +++ b/docs/FAQ/source/colorbar/ex_chaco_colorbar_03.py @@ -0,0 +1,196 @@ +#!/usr/bin/env python + +## ex_chaco_colorbar_03.py + +## -- Notes ----------------------------------------------------------------- + +## -- Imports --------------------------------------------------------------- +# standard imports +import os +from math import atan2, sqrt + +# numpy imports +from numpy import sin, cos, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits, Instance, Range, Str, on_trait_change +from traitsui.api import Item, Group, View + +# Chaco imports +from chaco.api import ArrayPlotData, jet, Plot, ColorBar +from chaco.api import LinearMapper, HPlotContainer + +## -- Defines --------------------------------------------------------------- +graphicWindowSize = (800,600) +colorbarWindowSize = (100,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +## -- Let's Begin ----------------------------------------------------------- + +## -- Functions ------------------------------------------------------------- + +## -- Classes --------------------------------------------------------------- + +class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + twoPi = 2.0 * pi + xA = linspace(-twoPi, twoPi, 600) + yA = linspace(-twoPi, twoPi, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + z1MG = exp(-(xMG**2 + yMG**2)) / 100.0 + zxMG = sin( xMG ) / xMG + zyMG = sin( yMG ) / yMG + zMG = zxMG + zyMG + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot + myTP = Plot( myAPD ) + + # add the image plot to this plot object + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = jet, + ) + + # add the title and padding around the plot + myTP.title = "2D sin(x)/x" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X Phase (rad)" + myTP.y_axis.title = "Y Phase (rad)" + + # add the colorbar + #myTCB = ColorBar( + # plot = myTP, + # index_mapper = LinearMapper( range = myTP.color_mapper.range ), + #) + + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + color_mapper = myTP.color_mapper, + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + #myTCB.plot = myTP + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + myHPC.bgcolor = "lightgray" + + # set up the view for both the graphics and control + + traits_view = View( + Group( + Item( 'myHPC', + editor = ComponentEditor( size = graphicWindowSize ), + show_label = False + ), + orientation = "vertical" + ), + resizable = True, + title = windowTitle, + ) + # padding=20) + + ## The border is visible (overrides enable.Component). + #border_visible = True + ## The orientation of the index axis. + #orientation = Enum('v', 'h') + ## Should the bar go left-to-right or bottom-to-top (normal) or the reverse? + #direction = Enum('normal', 'flipped') + ## Overrides the default background color trait in PlotComponent. + #bgcolor = 'transparent' + ## Draw layers in "draw order" + #use_draw_order = True + ## Default width is 40 pixels (overrides enable.CoordinateBox) + #width = 40 + + # Faux origin for the axis to look at + #origin = Enum('bottom left', 'top left', 'bottom right', 'top right') + + ## The border is visible (overrides enable.Component). + #border_visible = True + ## The orientation of the index axis. + #orientation = Enum('v', 'h') + ## Should the bar go left-to-right or bottom-to-top (normal) or the reverse? + #direction = Enum('normal', 'flipped') + ## Overrides the default background color trait in PlotComponent. + #bgcolor = 'transparent' + ## Draw layers in "draw order" + #use_draw_order = True + ## Default width is 40 pixels (overrides enable.CoordinateBox) + #width = 40 + # + ## Faux origin for the axis to look at + #origin = Enum('bottom left', 'top left', 'bottom right', 'top right') + + + + + # Dimensions that this component is resizable in. For resizable + # components, get_preferred_size() is called before their actual + # bounds are set. + # + # * 'v': resizable vertically + # * 'h': resizable horizontally + # * 'hv': resizable horizontally and vertically + # * '': not resizable + # + # Note that this setting means only that the *parent* can and should resize + # this component; it does *not* mean that the component automatically + # resizes itself. + #resizable = Enum("hv", "h", "v", "") + + + ##------------------------------------------------------------------------ + ## Border and background traits + ##------------------------------------------------------------------------ + # + ## The width of the border around this component. This is taken into account + ## during layout, but only if the border is visible. + #border_width = Int(1) + # + ## Is the border visible? If this is false, then all the other border + ## properties are not used. + #border_visible = Bool(False) + # + ## The line style (i.e. dash pattern) of the border. + #border_dash = LineStyle + # + ## The color of the border. Only used if border_visible is True. + #border_color = black_color_trait + # + ## The background color of this component. By default all components have + ## a white background. This can be set to "transparent" or "none" if the + ## component should be see-through. + #bgcolor = white_color_trait + + +## -- Main ------------------------------------------------------------------ + +if __name__ == "__main__": + + # build the object, and show the window + tP = TraitedPlot() + tP.configure_traits() + +## -- EOF ------------------------------------------------------------------- diff --git a/docs/FAQ/source/colorbar/foo.py b/docs/FAQ/source/colorbar/foo.py new file mode 100644 index 000000000..51d019351 --- /dev/null +++ b/docs/FAQ/source/colorbar/foo.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +from traits.api import HasTraits, Int + +class Boo( HasTraits ): + print( 'start Boo') + a = Int(5) + b = 12 + print( type(a) ) + print (type(b) ) + print( 'end Boo') + + def __init__(self): + print( '__init__' ) + + foo = 4 + +boo = Boo() +print( boo.a ) +print( boo.b ) +print( type(boo.a) ) +print (type(boo.b) ) + + diff --git a/docs/FAQ/source/colormapper/colormapper.rst b/docs/FAQ/source/colormapper/colormapper.rst new file mode 100644 index 000000000..5da819f81 --- /dev/null +++ b/docs/FAQ/source/colormapper/colormapper.rst @@ -0,0 +1,613 @@ +Color Mappers and Image Plots +============================= + +.. highlight:: python + :linenothreshold: 5 + +.. index:: + pair: Plot; ColorMapper + single: Function; Eggholder + +A colormap allows us to display a matrix of numbers as an image. Optionally, we +can place a colorbar object beside the image to indicate which colors map to +which values. + +Chaco Image Plot with ColorMapper +--------------------------------- + +Let's build a simple Chaco image plot and add a colorbar to it. This +plot uses defaults for the colormap, etc. A lot of things happen automatically:: + + ## ex_chaco_colormapper_01.py + + # standard imports + import os, inspect + + # numpy imports + from numpy import sin, sqrt,abs, exp, linspace, meshgrid, pi + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import ArrayPlotData, Plot, ColorBar + from chaco.api import LinearMapper, HPlotContainer + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + # Eggholder function + limitF = 500.0 + xA = linspace(-limitF, limitF, 600) + yA = linspace(-limitF, limitF, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 ))) + zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47)))) + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot. + myTP = Plot( myAPD ) + + # add the image plot to this plot object. If we don't specify the colormapper, + # it defaults to default_colormaps.Spectral + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + ) + + # add the title and padding around the plot + myTP.title = "Eggholder Function" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X" + myTP.y_axis.title = "Y" + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myHPC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + tp.myTP.color_mapper.print_traits() + tp.myTP.color_mapper.range.print_traits() + +The graphical output is: + +.. figure:: ex_chaco_colormapper_01.png + :scale: 100 % + :align: center + :alt: A Chaco image plot + + A simple Chaco image plot + +.. index + pair Colormap; Construction + +Colormap Construction +--------------------- + +Let's take more control over this plot. When using a colormap, we want to +map a 2D matrix of numbers (intensities) to various colors. We first construct +an ImageData object which describes the 2D matrix of number that we'll use for +the image source. We next build a DataRange1D instance from the ImageData +instance to describe the range of the values of the ImageData intensities. This +DataRange1D instance will be used to scale the color map. The code is:: + + # generate an ImageData instance and add our 2D image data to it. + myID = ImageData( ) + myID.set_data( zMG ) + + # build a DataRange1D instance to describe the ranges of the data in the + # image data + myDR1D = DataRange1D( myID ) + +Finally, we select a colormap function from the default_colormaps.py file. The +colormap names and functions are descibed in the +``default_colormaps.color_map_functions``, +``default_colormaps.color_map_dict``, and the +``default_colormaps.color_map_name_dict`` attributes. +:: + + myColorMapperFn = default_colormaps.color_map_name_dict['jet'] + +The ``default_colormaps`` module provides several functions to modify the +color map. The ``default_colormaps.reverse`` method takes a colormap function +and reverses it. +:: + + myColorMapperFn = default_colormaps.reverse( myColorMapperFn ) + +The ``default_colormaps.center`` method takes in a colormap and centers it +about a particular value. From the documentation, +:: + + For example, when passed a DataRange1D(low=-0.5, high=1.0), a colormap would + usually have its lowest color at -0.5 and its highest at 1.0. Some colormaps + are designed such that the middle color is special. Using this modifier, the + example range would be modified to -1.0 and 1.0 to make 0.0 correspond with + the middle color. + + myColorMapperFn = default_colormaps.center( myColorMapperFn,500 ) + +The ``default_colormaps.fix()`` method sets the minimum and maximum saturation +values for the colormap. + + myColorMapperFn = default_colormaps.fix( myColorMapperFn,(-500,500) ) + +We can also use the ``myTP.color_mapper.range.low_setting`` and +``myTP.color_mapper.range.high_setting`` to modify the colormapper range +at any time. +:: + + myTP.color_mapper.range.low_setting = 0 + myTP.color_mapper.range.high_setting = 1000 + +We finally build the scaled color mapping function and apply it to the image +plot with:: + + myColorMapper = myColorMapperFn( myDR1D ) + + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = myColorMapper, + ) + +The complete code, containing hooks to modify a colormap, is:: + + ## ex_chaco_colormapper_02.py + + # standard imports + import os, inspect + + # numpy imports + from numpy import sin, sqrt,abs, exp, linspace, meshgrid, pi + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import ArrayPlotData, Plot, ColorBar + from chaco.api import LinearMapper, HPlotContainer + from chaco.api import ImageData, DataRange1D + + from chaco import default_colormaps + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + # Eggholder function + limitF = 500.0 + xA = linspace(-limitF, limitF, 600) + yA = linspace(-limitF, limitF, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 ))) + zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47)))) + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot + myTP = Plot( myAPD ) + + # contains a dict of default colormaps and their functions. We have to + # pass the colormapper the data range of interest to set up the private + # attributes + default_colormaps.color_map_name_dict + + # the colormap method needs the range of the image data that we want to + # plot. We first put the image data (zMG) into an ImageData object. We + # then use DataRange1D on the ImageData instance to produce a DataRange1D + # instance describing the ImageData data. Finally, we feed the DataRange1D + # instance into the colormapper to produce a working colormapper. + myID = ImageData( ) + myID.set_data( zMG ) + myDR1D = DataRange1D( myID ) + + # pick a colormap + myColorMapperFn = default_colormaps.color_map_name_dict['copper'] + + # choose one or more modifications to the colormap function + #myColorMapperFn = default_colormaps.reverse( myColorMapperFn ) + #myColorMapperFn = default_colormaps.center( myColorMapperFn,500 ) + #myColorMapperFn = default_colormaps.fix( myColorMapperFn,(-500,500) ) + + # finally, build the colormapper function + myColorMapper = myColorMapperFn( myDR1D ) + + # add the image plot to this plot object + # specify the colormap explicitly + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = myColorMapper, + ) + + # add the title and padding around the plot + myTP.title = "Eggholder Function" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X" + myTP.y_axis.title = "Y" + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # range of the colormapper. Changes the min/max values that are mapped + # to the ends of the color range. Try +/-2000 for poor contrast and +/-200 for + # saturated. Asymmetrical values work as well. + #myTP.color_mapper.range.low_setting = 0 + #myTP.color_mapper.range.high_setting = 1000 + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myHPC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + myMethods = inspect.getmembers(tp.myTP.color_mapper) + myPublics = [thisItem for thisItem in myMethods if thisItem[0][0] != '_'] + print( myPublics ) + + tp.myTP.color_mapper.print_traits() + tp.myTP.color_mapper.range.print_traits() + + print( default_colormaps.__all__ ) + print( default_colormaps.color_map_dict ) + print( default_colormaps.color_map_name_dict ) + +The graphical output is: + +.. figure:: ex_chaco_colormapper_02.png + :scale: 100 % + :align: center + :alt: A Chaco image plot, with color map modifications + + A Chaco image plot, with color map modifications + +.. index:: + pair: Colormapped Plot; Traits + +Colormapped Plot with Traits +---------------------------- + +Finally, we present a colormapped plot whose parameters are wired up as Traited +variables. We can reverse, set limits and select the colormap via the TraitsUI +widgets at the bottom of the plot. The source is:: + + ## ex_chaco_colormapper_04.py + + # standard imports + import os, inspect + + # numpy imports + from numpy import sin, sqrt,abs, exp, linspace, meshgrid, pi + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits, Instance, Enum, Range, Bool + from traitsui.api import Item, Group, VGroup, View, RangeEditor + from chaco.api import ArrayPlotData, Plot, ColorBar + from chaco.api import LinearMapper, HPlotContainer + from chaco.api import ImageData, DataRange1D + + from chaco import default_colormaps + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + # the Traits Plot Container + myTP = Instance( Plot ) + myTCB = Instance( ColorBar ) + myTIC = Instance( HPlotContainer ) + + # contains a list of default colormap names + colormapNameTE = Enum( + default_colormaps.color_map_name_dict.keys(), + label = 'Color Map Name', + desc = 'the color map name', + ) + + # the low saturation value for the colormap + colormapLowTR = Range( + value = -1000, + low = -1000, + high = 1000, + label = 'Color Map Low', + desc = 'the color map low saturation value', + ) + + colormapHighTR = Range( + value = 1000, + low = -1000, + high = 1000, + label = 'Color Map High', + desc = 'the color map high saturation value', + ) + + reversedColormapTB = Bool( + value = False, + label = 'Reverse the Color Map', + desc = 'the color map reversal state', + ) + + # set up the view for both the graphics and control + traits_view = View( + Item( + name = 'myTIC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + Item( name = "colormapNameTE" ), + Item( + name = "colormapLowTR", + editor = RangeEditor( + auto_set = False, + enter_set = True, + mode = 'slider', + low = -1000, + high = 1000, + ), + ), + Item( + name = "colormapHighTR", + editor = RangeEditor( + auto_set = False, + enter_set = True, + mode = 'slider', + low = -1000, + high = 1000, + ), + ), + Item( name = "reversedColormapTB" ), + resizable = True, + title = windowTitle, + ) + + def _myTIC_default( self ): + + # create an interesting scalar field for the image plot + # Eggholder function + limitF = 500.0 + xA = linspace(-limitF, limitF, 600) + yA = linspace(-limitF, limitF, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 ))) + zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47)))) + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot + self.myTP = Plot( myAPD ) + + # contains a dict of default colormaps and their functions. We have to + # pass the colormapper the data range of interest to set up the private + # attributes + default_colormaps.color_map_name_dict + + # the colormap method needs the range of the image data that we want to + # plot. We first put the image data (zMG) into an ImageData object. We + # then use DataRange1D on the ImageData instance to produce a DataRange1D + # instance describing the ImageData data. Finally, we feed the DataRange1D + # instance into the colormapper to produce a working colormapper. + myID = ImageData( ) + myID.set_data( zMG ) + self.myDR1D = DataRange1D( myID ) + + # pick an unmodified (i.e. unreversed, no ranges) colormap and build + # the colormap functions + myColorMapperFn = default_colormaps.color_map_name_dict[self.colormapNameTE] + myColorMapper = myColorMapperFn( self.myDR1D ) + + # add the image plot to this plot object + # specify the colormap explicitly + self.myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = myColorMapper, + ) + + # add the title and padding around the plot + self.myTP.title = "Eggholder Function" + self.myTP.padding = 50 + + # grids, fonts, etc + self.myTP.x_axis.title = "X" + self.myTP.y_axis.title = "Y" + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + self.myTCB = ColorBar( + plot = self.myTP, + index_mapper = LinearMapper( range = self.myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + self.myTCB.padding_top = self.myTP.padding_top + self.myTCB.padding_bottom = self.myTP.padding_bottom + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( self.myTP ) + myHPC.add( self.myTCB ) + + return( myHPC ) + + def _modify_colormap(self): + + #myTP.color_mapper.range.low_setting = 0 + #myTP.color_mapper.range.high_setting = 1000 + + # pick out the color map function + myColorMapperFn = default_colormaps.color_map_name_dict[self.colormapNameTE] + + # reverse the colormap, if req'd + if self.reversedColormapTB: + myColorMapperFn = default_colormaps.reverse( myColorMapperFn ) + + ## TODO adjust for too low, too high, end cases + + myColorMapperFn = default_colormaps.fix( + myColorMapperFn, + (self.colormapLowTR, self.colormapHighTR) + ) + myColorMapper = myColorMapperFn( self.myDR1D ) + self.myTP.color_mapper = myColorMapper + self.myTP.request_redraw() + + def _reversedColormapTB_changed( self,old,new ): + S = '_reversedColormapTB_changed() - old: %s, new: %s' % (old,new) + print( S ) + self._modify_colormap() + + def _colormapNameTE_changed( self,old,new ): + S = '_colormapNameTE_changed() - old: %s, new: %s' % (old,new) + print( S ) + self._modify_colormap() + + def _colormapLowTR_changed( self,old,new ): + S = '_colormapLowTR_changed() - old: %s, new: %s' % (old,new) + print( S ) + + # check for boundary conditions + if self.colormapLowTR >= self.colormapHighTR: + self.colormapLowTR = old + print( 'colormapLowTR restored to old value: %s' % old ) + self._modify_colormap() + + def _colormapHighTR_changed( self,old,new ): + S = '_colormapHighTR_changed() - old: %s, new: %s' % (old,new) + print( S ) + if self.colormapHighTR <= self.colormapLowTR: + self.colormapHighTR = old + print( 'colormapHighTR restored to old value: %s' % old ) + self._modify_colormap() + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits( ) + +The graphical output is: + +.. figure:: ex_chaco_colormapper_04.png + :scale: 100 % + :align: center + :alt: A Chaco image plot, with Traited characteristics + + A Chaco image plot, with Traited characteristics + +Found Code +---------- + +from plot.py:: + + if colormap is None: + if self.color_mapper is None: + colormap = Spectral(DataRange1D(value)) + else: + colormap = self.color_mapper + elif isinstance(colormap, AbstractColormap): + if colormap.range is None: + colormap.range = DataRange1D(value) + else: + colormap = colormap(DataRange1D(value)) + self.color_mapper = colormap + cls = self.renderer_map["cmap_img_plot"] + kwargs = dict(value_mapper=colormap, **styles) + + + diff --git a/docs/FAQ/source/colormapper/ex_chaco_colormapper_01.png b/docs/FAQ/source/colormapper/ex_chaco_colormapper_01.png new file mode 100644 index 000000000..ca1b3d00e Binary files /dev/null and b/docs/FAQ/source/colormapper/ex_chaco_colormapper_01.png differ diff --git a/docs/FAQ/source/colormapper/ex_chaco_colormapper_01.py b/docs/FAQ/source/colormapper/ex_chaco_colormapper_01.py new file mode 100644 index 000000000..050c823ae --- /dev/null +++ b/docs/FAQ/source/colormapper/ex_chaco_colormapper_01.py @@ -0,0 +1,94 @@ +## ex_chaco_colormapper_01.py + +# standard imports +import os, inspect + +# numpy imports +from numpy import sin, sqrt,abs, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import ArrayPlotData, Plot, ColorBar +from chaco.api import LinearMapper, HPlotContainer + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + # Eggholder function + limitF = 500.0 + xA = linspace(-limitF, limitF, 600) + yA = linspace(-limitF, limitF, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 ))) + zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47)))) + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot. + myTP = Plot( myAPD ) + + # add the image plot to this plot object. If we don't specify the colormapper, + # it defaults to default_colormaps.Spectral + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + ) + + # add the title and padding around the plot + myTP.title = "Eggholder Function" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X" + myTP.y_axis.title = "Y" + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myHPC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + tp.myTP.color_mapper.print_traits() + tp.myTP.color_mapper.range.print_traits() diff --git a/docs/FAQ/source/colormapper/ex_chaco_colormapper_02.png b/docs/FAQ/source/colormapper/ex_chaco_colormapper_02.png new file mode 100644 index 000000000..5a6d5346b Binary files /dev/null and b/docs/FAQ/source/colormapper/ex_chaco_colormapper_02.png differ diff --git a/docs/FAQ/source/colormapper/ex_chaco_colormapper_02.py b/docs/FAQ/source/colormapper/ex_chaco_colormapper_02.py new file mode 100644 index 000000000..050cdaabc --- /dev/null +++ b/docs/FAQ/source/colormapper/ex_chaco_colormapper_02.py @@ -0,0 +1,137 @@ +## ex_chaco_colormapper_02.py + +# standard imports +import os, inspect + +# numpy imports +from numpy import sin, sqrt,abs, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import ArrayPlotData, Plot, ColorBar +from chaco.api import LinearMapper, HPlotContainer +from chaco.api import ImageData, DataRange1D + +from chaco import default_colormaps + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + # Eggholder function + limitF = 500.0 + xA = linspace(-limitF, limitF, 600) + yA = linspace(-limitF, limitF, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 ))) + zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47)))) + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot + myTP = Plot( myAPD ) + + # contains a dict of default colormaps and their functions. We have to + # pass the colormapper the data range of interest to set up the private + # attributes + default_colormaps.color_map_name_dict + + # the colormap method needs the range of the image data that we want to + # plot. We first put the image data (zMG) into an ImageData object. We + # then use DataRange1D on the ImageData instance to produce a DataRange1D + # instance describing the ImageData data. Finally, we feed the DataRange1D + # instance into the colormapper to produce a working colormapper. + myID = ImageData( ) + myID.set_data( zMG ) + myDR1D = DataRange1D( myID ) + + # pick a colormap + myColorMapperFn = default_colormaps.color_map_name_dict['copper'] + + # choose one or more modifications to the colormap function + #myColorMapperFn = default_colormaps.reverse( myColorMapperFn ) + #myColorMapperFn = default_colormaps.center( myColorMapperFn,500 ) + #myColorMapperFn = default_colormaps.fix( myColorMapperFn,(-500,500) ) + + # finally, build the colormapper function + myColorMapper = myColorMapperFn( myDR1D ) + + # add the image plot to this plot object + # specify the colormap explicitly + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = myColorMapper, + ) + + # add the title and padding around the plot + myTP.title = "Eggholder Function" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X" + myTP.y_axis.title = "Y" + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # range of the colormapper. Changes the min/max values that are mapped + # to the ends of the color range. Try +/-2000 for poor contrast and +/-200 for + # saturated. Asymmetrical values work as well. + #myTP.color_mapper.range.low_setting = 0 + #myTP.color_mapper.range.high_setting = 1000 + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myHPC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + myMethods = inspect.getmembers(tp.myTP.color_mapper) + myPublics = [thisItem for thisItem in myMethods if thisItem[0][0] != '_'] + print( myPublics ) + + tp.myTP.color_mapper.print_traits() + tp.myTP.color_mapper.range.print_traits() + + print( default_colormaps.__all__ ) + print( default_colormaps.color_map_dict ) + print( default_colormaps.color_map_name_dict ) diff --git a/docs/FAQ/source/colormapper/ex_chaco_colormapper_03.py b/docs/FAQ/source/colormapper/ex_chaco_colormapper_03.py new file mode 100644 index 000000000..edd4ef6d2 --- /dev/null +++ b/docs/FAQ/source/colormapper/ex_chaco_colormapper_03.py @@ -0,0 +1,133 @@ +## ex_chaco_colormapper_03.py + +# standard imports +import os, inspect + +# numpy imports +from numpy import sin, sqrt,abs, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits, Instance +from traitsui.api import Item, Group, View +from chaco.api import ArrayPlotData, Plot, ColorBar +from chaco.api import LinearMapper, HPlotContainer +from chaco.api import ImageData, DataRange1D + +from chaco import default_colormaps + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + # the plot container + myTIC = Instance( HPlotContainer ) + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myTIC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + + def _myTIC_default( self ): + + # create an interesting scalar field for the image plot + # Eggholder function + limitF = 500.0 + xA = linspace(-limitF, limitF, 600) + yA = linspace(-limitF, limitF, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 ))) + zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47)))) + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot + myTP = Plot( myAPD ) + + # contains a dict of default colormaps and their functions. We have to + # pass the colormapper the data range of interest to set up the private + # attributes + default_colormaps.color_map_name_dict + + # the colormap method needs the range of the image data that we want to + # plot. We first put the image data (zMG) into an ImageData object. We + # then use DataRange1D on the ImageData instance to produce a DataRange1D + # instance describing the ImageData data. Finally, we feed the DataRange1D + # instance into the colormapper to produce a working colormapper. + myID = ImageData( ) + myID.set_data( zMG ) + myDR1D = DataRange1D( myID ) + + # pick a colormap + myColorMapperFn = default_colormaps.color_map_name_dict['copper'] + + # choose one or more modifications to the colormap function + #myColorMapperFn = default_colormaps.reverse( myColorMapperFn ) + #myColorMapperFn = default_colormaps.center( myColorMapperFn,500 ) + #myColorMapperFn = default_colormaps.fix( myColorMapperFn,(-500,500) ) + + # finally, build the colormapper function + myColorMapper = myColorMapperFn( myDR1D ) + + # add the image plot to this plot object + # specify the colormap explicitly + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = myColorMapper, + ) + + # add the title and padding around the plot + myTP.title = "Eggholder Function" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X" + myTP.y_axis.title = "Y" + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # range of the colormapper. Changes the min/max values that are mapped + # to the ends of the color range. Try +/-2000 for poor contrast and +/-200 for + # saturated. Asymmetrical values work as well. + #myTP.color_mapper.range.low_setting = 0 + #myTP.color_mapper.range.high_setting = 1000 + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + + return( myHPC ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits( ) diff --git a/docs/FAQ/source/colormapper/ex_chaco_colormapper_04.png b/docs/FAQ/source/colormapper/ex_chaco_colormapper_04.png new file mode 100644 index 000000000..8418f6602 Binary files /dev/null and b/docs/FAQ/source/colormapper/ex_chaco_colormapper_04.png differ diff --git a/docs/FAQ/source/colormapper/ex_chaco_colormapper_04.py b/docs/FAQ/source/colormapper/ex_chaco_colormapper_04.py new file mode 100644 index 000000000..d465da609 --- /dev/null +++ b/docs/FAQ/source/colormapper/ex_chaco_colormapper_04.py @@ -0,0 +1,225 @@ +## ex_chaco_colormapper_04.py + +# standard imports +import os, inspect + +# numpy imports +from numpy import sin, sqrt,abs, exp, linspace, meshgrid, pi + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits, Instance, Enum, Range, Bool +from traitsui.api import Item, Group, VGroup, View, RangeEditor +from chaco.api import ArrayPlotData, Plot, ColorBar +from chaco.api import LinearMapper, HPlotContainer +from chaco.api import ImageData, DataRange1D + +from chaco import default_colormaps + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + # the Traits Plot Container + myTP = Instance( Plot ) + myTCB = Instance( ColorBar ) + myTIC = Instance( HPlotContainer ) + + # contains a list of default colormap names + colormapNameTE = Enum( + default_colormaps.color_map_name_dict.keys(), + label = 'Color Map Name', + desc = 'the color map name', + ) + + # the low saturation value for the colormap + colormapLowTR = Range( + value = -1000, + low = -1000, + high = 1000, + label = 'Color Map Low', + desc = 'the color map low saturation value', + ) + + colormapHighTR = Range( + value = 1000, + low = -1000, + high = 1000, + label = 'Color Map High', + desc = 'the color map high saturation value', + ) + + reversedColormapTB = Bool( + value = False, + label = 'Reverse the Color Map', + desc = 'the color map reversal state', + ) + + # set up the view for both the graphics and control + traits_view = View( + Item( + name = 'myTIC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + Item( name = "colormapNameTE" ), + Item( + name = "colormapLowTR", + editor = RangeEditor( + auto_set = False, + enter_set = True, + mode = 'slider', + low = -1000, + high = 1000, + ), + ), + Item( + name = "colormapHighTR", + editor = RangeEditor( + auto_set = False, + enter_set = True, + mode = 'slider', + low = -1000, + high = 1000, + ), + ), + Item( name = "reversedColormapTB" ), + resizable = True, + title = windowTitle, + ) + + def _myTIC_default( self ): + + # create an interesting scalar field for the image plot + # Eggholder function + limitF = 500.0 + xA = linspace(-limitF, limitF, 600) + yA = linspace(-limitF, limitF, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 ))) + zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47)))) + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot + self.myTP = Plot( myAPD ) + + # contains a dict of default colormaps and their functions. We have to + # pass the colormapper the data range of interest to set up the private + # attributes + default_colormaps.color_map_name_dict + + # the colormap method needs the range of the image data that we want to + # plot. We first put the image data (zMG) into an ImageData object. We + # then use DataRange1D on the ImageData instance to produce a DataRange1D + # instance describing the ImageData data. Finally, we feed the DataRange1D + # instance into the colormapper to produce a working colormapper. + myID = ImageData( ) + myID.set_data( zMG ) + self.myDR1D = DataRange1D( myID ) + + # pick an unmodified (i.e. unreversed, no ranges) colormap and build + # the colormap functions + myColorMapperFn = default_colormaps.color_map_name_dict[self.colormapNameTE] + myColorMapper = myColorMapperFn( self.myDR1D ) + + # add the image plot to this plot object + # specify the colormap explicitly + self.myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + colormap = myColorMapper, + ) + + # add the title and padding around the plot + self.myTP.title = "Eggholder Function" + self.myTP.padding = 50 + + # grids, fonts, etc + self.myTP.x_axis.title = "X" + self.myTP.y_axis.title = "Y" + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + self.myTCB = ColorBar( + plot = self.myTP, + index_mapper = LinearMapper( range = self.myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + self.myTCB.padding_top = self.myTP.padding_top + self.myTCB.padding_bottom = self.myTP.padding_bottom + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( self.myTP ) + myHPC.add( self.myTCB ) + + return( myHPC ) + + def _modify_colormap(self): + + #myTP.color_mapper.range.low_setting = 0 + #myTP.color_mapper.range.high_setting = 1000 + + # pick out the color map function + myColorMapperFn = default_colormaps.color_map_name_dict[self.colormapNameTE] + + # reverse the colormap, if req'd + if self.reversedColormapTB: + myColorMapperFn = default_colormaps.reverse( myColorMapperFn ) + + ## TODO adjust for too low, too high, end cases + + myColorMapperFn = default_colormaps.fix( + myColorMapperFn, + (self.colormapLowTR, self.colormapHighTR) + ) + myColorMapper = myColorMapperFn( self.myDR1D ) + self.myTP.color_mapper = myColorMapper + self.myTP.request_redraw() + + def _reversedColormapTB_changed( self,old,new ): + S = '_reversedColormapTB_changed() - old: %s, new: %s' % (old,new) + print( S ) + self._modify_colormap() + + def _colormapNameTE_changed( self,old,new ): + S = '_colormapNameTE_changed() - old: %s, new: %s' % (old,new) + print( S ) + self._modify_colormap() + + def _colormapLowTR_changed( self,old,new ): + S = '_colormapLowTR_changed() - old: %s, new: %s' % (old,new) + print( S ) + + # check for boundary conditions + if self.colormapLowTR >= self.colormapHighTR: + self.colormapLowTR = old + print( 'colormapLowTR restored to old value: %s' % old ) + self._modify_colormap() + + def _colormapHighTR_changed( self,old,new ): + S = '_colormapHighTR_changed() - old: %s, new: %s' % (old,new) + print( S ) + if self.colormapHighTR <= self.colormapLowTR: + self.colormapHighTR = old + print( 'colormapHighTR restored to old value: %s' % old ) + self._modify_colormap() + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits( ) diff --git a/docs/FAQ/source/conf.py b/docs/FAQ/source/conf.py new file mode 100644 index 000000000..7238c8c00 --- /dev/null +++ b/docs/FAQ/source/conf.py @@ -0,0 +1,242 @@ +# -*- coding: utf-8 -*- +# +# FAQ documentation build configuration file, created by +# sphinx-quickstart on Thu Feb 28 06:48:12 2013. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.todo'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Chaco FAQ' +copyright = u'2013, KJM' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.1' +# The full version, including alpha/beta/rc tags. +release = '0.1' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'FAQdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('index', 'FAQ.tex', u'FAQ Documentation', + u'KJM', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'faq', u'FAQ Documentation', + [u'KJM'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'FAQ', u'FAQ Documentation', + u'KJM', 'FAQ', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' diff --git a/docs/FAQ/source/elementsChacoLinePlot/elementsChacoLinePlot.rst b/docs/FAQ/source/elementsChacoLinePlot/elementsChacoLinePlot.rst new file mode 100644 index 000000000..52e136f89 --- /dev/null +++ b/docs/FAQ/source/elementsChacoLinePlot/elementsChacoLinePlot.rst @@ -0,0 +1,1007 @@ +Elements of a Chaco Line Plot +============================= + +.. highlight:: python + :linenothreshold: 5 + +Let's build a minimalist Chaco line plot and introspect into the elements +underneath it. We're looking for the elements that control the behavior of the +plot (e.g. axis labels, line width, background color, etc). In further chapters, +we'll modify these attributes to control the look of the plot. + +.. index:: + pair: Plot; Minimalist + single: Line Plot; Minimalist + +Minimal Chaco Line Plot +------------------------ + +The source for a very minimal Chaco line plot is:: + + ## ex_chaco_line_01.py + + # standard imports + import os, inspect + import numpy as np + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import Plot, ArrayPlotData + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + # generate interesting data + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + # map arrays to plot names. TADP suffix => Traits ArrayPlotData + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + # generate the plot. TP suffix => Traits Plot + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # generate the view + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + # generate and display the plot + tp = TraitedPlot() + tp.configure_traits() + + # after we close the plot, all the attributes of the plot will be set (see + # Lazy Initialization). Introspect into the tp object + + # generate a list of the public attributes in the Traits Plot objext + myPublics = [thisItem for thisItem in inspect.getmembers(tp.myTP) if thisItem[0][0] != '_'] + print( myPublics ) + + # use the print_traits() method to show a subset of the plot attributes + tp.myTP.print_traits() + +The resulting graphic is + +.. figure:: ex_chaco_line_01.png + :scale: 100 % + :align: center + :alt: A simple Chaco line plot + + A simple Chaco line plot + +.. index:: + single: Plot; getmembers + single: Line Plot; getmembers + single: Plot; print_traits() + single: Line Plot; print_traits() + single: print_traits(); Line Plot + single: print_traits(); Plot + + +The reader is encouraged to examine the ``myPublics`` list and the output of +the ``tp.myTP.print_traits()`` command. This data describes how the +attributes of a Chaco plot come together. The various outputs are also available +under the 'Excruciating Detail' heading below + +.. index:: + pair: Line Plot; Data + +Plot Data +--------- + +Let's first look at the sources of data for the plot. Two likely candidates +are the ``data`` and ``datasources`` attributes from the ``myPublics`` list:: + + ('data', ), + ('datasources', + { 'Y': , + 'X': }), + +.. index:: + pair: Line Plot; ArrayPlotData + pair: ArrayPlotData; print_traits() + +ArrayPlotData +------------- + +We first note that the 'data' attribute of the ``myTP`` object is the same as the +``myTAPD`` object in which we first placed the data:: + + tp.myTP.data + + tp.myTADP + + +The ArrayPlotData object maps plot names to data arrays. It's defined in the +chaco/array_plot_data.py module. Introspecting into ``tp.myTP.data`` +produces:: + + tp.myTP.data + + + tp.myTP.data.print_traits() + arrays: {'Y': array([ 4.57391553e-19, ...923, 6.15625227, 6.28318531])} + selectable: True + writable: True + + tp.myTP.data.__dict__ + {'arrays': + { 'Y': array([ + 4.57391553e-19, 2.68399330e-04, 6.04546385e-04, + 1.01572218e-03, 1.50856699e-03, 2.08865225e-03, + ...... + -1.01572218e-03, -6.04546385e-04, -2.68399330e-04, + -4.57391553e-19]), + 'X': array([ + -6.28318531, -6.15625227, -6.02931923, -5.9023862 , -5.77545316, + -5.64852012, -5.52158709, -5.39465405, -5.26772102, -5.14078798, + ...... + 5.14078798, 5.26772102, 5.39465405, 5.52158709, 5.64852012, + 5.77545316, 5.9023862 , 6.02931923, 6.15625227, 6.28318531])}, + 'writable': True} + +The ``writable`` flag indicates that we're allowed to write to this data. The +``arrays`` attribute contains the data arrays assocated with this object. +These are the arrays and names we passed to the original ``myTADP.set_data`` +calls. + +.. index:: + pair: ArrayDataSource; print_traits() + +ArrayDataSource +--------------- + +The ``datasources`` dictionary contains an entry for both the X and Y +arrays:: + + ('datasources', + { 'Y': , + 'X': }), + +The ArrayDataSource objects describes a single, continuous array of +numerical data. The object contains the raw data (without a useful label) +along with some descriptors about the array:: + + tp.myTP.datasources['X'] + + + tp.myTP.datasources['X'].print_traits() + _cached_bounds: (-6.2831853071795862, 6.2831853071795862) + _cached_mask: None + _data: array([-6.28318531, -6.1562522...3, 6.15625227, 6.28318531]) + _max_index: 99 + _min_index: 0 + index_dimension: 'scalar' + metadata: {'annotations': [], 'selections': []} + persist_data: True + sort_order: 'none' + value_dimension: 'scalar' + + tp.myTP.datasources['X'].__dict__ + { + '_max_index': 99, + '_cached_bounds': (-6.2831853071795862, 6.2831853071795862), + '_data': + array([-6.28318531, -6.15625227, -6.02931923, -5.9023862 , -5.77545316, + -5.64852012, -5.52158709, -5.39465405, -5.26772102, -5.14078798, + ...... + 5.14078798, 5.26772102, 5.39465405, 5.52158709, 5.64852012, + 5.77545316, 5.9023862 , 6.02931923, 6.15625227, 6.28318531]), + 'sort_order': 'none', + '_min_index': 0 + } + +Typically, the user passes the Array and the ``sort_order`` flag to the +ArrayDataSource construct and the method builds the private characteristics +that describe the array. Such descriptors include ``_min_index``, ``_max_index``, +``_cached_bounds``, etc. + +The ``sort_order`` flag does not tell the method to sort the user's array. The +flag is meant to inform follow-on processors that the data in the array is sorted. +Options for ``sort_order`` are 'none','ascending' and 'descending.' + +.. index:: + single: padding + single: padding_bottom + single: padding_top + single: padding_left + single: padding_right + +Padding +------- + +The padding attributes represent the number of pixels between the plot and the +window edge. This is the space for axes labels, tick marks, etc. The fundamental +attributes are:: + + [padding_left, padding_right, padding_top, padding_bottom] + +Retrive the padding using:: + + tp.myTP.padding + [50, 50, 50, 50] + # returns [padding_left, padding_right, padding_top, padding_bottom] + +You can also set equal padding by:: + + tp.myTP.padding = 25 + # results in padding of [25,25,25,25] + +.. index:: + pair: Grids; Plot + +Grids +----- + +You can access the characteristics of the plot grid using the following +commands:: + + tp.myTP.x_grid + tp.myTP.x_grid.print_traits() + +.. index:: + single: Axis + single: Axes + +Axes +---- + +View the axes characteristics of the plot with:: + + tp.myTP.x_axis + tp.myTP.x_axis.print_traits() + +.. index:: + pair: Range; Plot + +Plotting Ranges +--------------- + +The x- and y-ranges of the plot are revealed using:: + + tp.myTP.range2d.print_traits() + +The ``range2d`` attribute contains both an ``x_range`` and a ``y_range`` object. +Let's look at the ``x_range`` object:: + + tp.myTP.range2d.x_range + tp.myTP.range2d.x_range.print_traits() + +Excruciating Detail +------------------- + +.. index + pair: Plot; print_traits() + +The ``myPublics`` list contains the public attributes of the ``tp.myTP`` +object:: + + [ + ('accepts_focus', True), + ('add', >), + ('add_class_trait', >), + ('add_trait', >), + ('add_trait_category', >), + ('add_trait_listener', >), + ('add_xy_plot', >), + ('all_trait_names', >), + ('as_coordinates', >), + ('aspect_ratio', None), + ('auto_handle_event', False), + ('auto_size', False), + ('base_trait', >), + ('bgcolor', 'white'), + ('bgcolor_', (1.0, 1.0, 1.0, 1.0)), + ('border_color_', (0.0, 0.0, 0.0, 1.0)), + ('border_dash_', None), + ('border_visible', True), + ('border_width', 1), + ('bounds', [700, 500]), + ('candle_plot', >), + ('class_default_traits_view', >), + ('class_editable_traits', >), + ('class_trait_names', >), + ('class_trait_view', >), + ('class_trait_view_elements', >), + ('class_traits', >), + ('cleanup', >), + ('clone_traits', >), + ('compact', >), + ('components_at', >), + ('configure_traits', >), + ('container', None), + ('container_under_layers', + ( 'background', + 'image', + 'underlay', + 'plot')), + ('contour_plot', >), + ('controller', None), + ('copy_traits', >), + ('copyable_trait_names', >), + ('data', ), + ('datasources', + { 'Y': , + 'X': }), + ('default_index', ), + ('default_origin', 'bottom left'), + ('default_traits_view', >), + ('delplot', >), + ('dispatch', >), + ('do_layout', >), + ('draw', >), + ('draw_order', + [ 'background', + 'image', + 'underlay', + 'plot', + 'selection', + 'border', + 'annotation', + 'overlay']), + ('draw_select_box', >), + ('draw_valid', False), + ('drawn_outer_bounds', [800, 600]), + ('drawn_outer_position', [0, 0]), + ('edit_traits', >), + ('editable_traits', >), + ('event_state', 'normal'), + ('fill_padding', False), + ('fit_window', True), + ('get', >), + ('get_absolute_coords', >), + ('get_event_transform', >), + ('get_preferred_size', >), + ('has_traits_interface', >), + ('hideplot', >), + ('img_plot', >), + ('index_mapper', ), + ('index_scale', 'linear'), + ('insert', >), + ('inset_border', True), + ('invalidate_and_redraw', >), + ('invalidate_draw', >), + ('is_in', >), + ('legend', ), + ('lower_component', >), + ('map_data', >), + ('map_screen', >), + ('new_window', >), + ('normal_mouse_leave', >), + ('on_trait_change', >), + ('on_trait_event', >), + ('orientation', 'h'), + ('overlay_border', True), + ('overlays', + [ , + ]), + ('padding_accepts_focus', True), + ('padding_bottom', 50), + ('padding_left', 50), + ('padding_right', 50), + ('padding_top', 50), + ('parent', None), + ('plot', >), + ('plots', + { 'plot0': []}), + ('position', [50, 50]), + ('print_traits', >), + ('raise_component', >), + ('range2d', ), + ('remove', >), + ('remove_trait', >), + ('remove_trait_listener', >), + ('renderer_map', {'bar': , 'filled_line': , 'cmap_img_plot': , 'cmap_scatter': , 'contour_poly_plot': , 'img_plot': , 'contour_line_plot': , 'candle': , 'line': , 'scatter': , 'polygon': }), + ('request_redraw', >), + ('reset_traits', >), + ('resizable', 'hv'), + ('set', >), + ('set_outer_bounds', >), + ('set_outer_position', >), + ('set_trait_dispatch_handler', >), + ('showplot', >), + ('sync_trait', >), + ('tools', []), + ('trait', >), + ('trait_context', >), + ('trait_get', >), + ('trait_items_event', ), + ('trait_monitor', >), + ('trait_names', >), + ('trait_property_changed', ), + ('trait_set', >), + ('trait_setq', >), + ('trait_subclasses', >), + ('trait_view', >), + ('trait_view_elements', >), + ('trait_views', >), + ('traits', >), + ('traits_init', ), + ('traits_inited', ), + ('underlays', + [ , + , + , + ]), + ('use_backbuffer', False), + ('use_draw_order', True), + ('validate_trait', >), + ('value_mapper', ), + ('value_scale', 'linear'), + ('viewports', []), + ('visible', True), + ('wrappers', + { 'new': , + 'ui': , + 'extended': , + 'fast_ui': , + 'same': }), + ('x_axis', ), + ('x_grid', ), + ('y_axis', ), + ('y_grid', ) + ] + +The ``tp.myTP.print_traits()`` method produces:: + + _active_tool: None + _auto_color_idx: -1 + _auto_edge_color_idx: -1 + _auto_face_color_idx: -1 + _backbuffer: None + _cached_preferred_size: () + _children_draw_mode: 'default' + _components: [] + _layout_needed: False + _lookup_cache: None + _plot_ui_info: None + _prev_event_handlers: set([]) + _title: + _window: None + accepts_focus: True + active_tool: None + aspect_ratio: None + auto_center: True + auto_colors: ['green', 'lightgreen', 'b...nk', 'darkgray', 'silver'] + auto_handle_event: False + auto_size: False + backbuffer_padding: True + bgcolor: 'white' + bgcolor_: (1.0, 1.0, 1.0, 1.0) + border_color: 'black' + border_color_: (0.0, 0.0, 0.0, 1.0) + border_dash: 'solid' + border_dash_: None + border_visible: True + border_width: 1 + bounds: [700, 500] + classes: [] + color_mapper: None + components: [] + container: None + container_under_layers: ('background', 'image', 'underlay', 'plot') + controller: None + cursor_color: 'black' + cursor_style: 'default' + data: + datasources: {'Y': } + default_index: + default_origin: 'bottom left' + default_size: (0, 0) + draw_layer: 'plot' + draw_order: ['background', 'image', 'u..., 'annotation', 'overlay'] + draw_valid: False + drawn_outer_bounds: [800, 600] + drawn_outer_position: [0, 0] + event_state: 'normal' + fill_padding: False + fit_components: '' + fit_window: True + fixed_preferred_size: None + height: 500 + hpadding: 100 + id: '' + index_axis: + index_grid: + index_mapper: + index_range: + index_scale: 'linear' + inset_border: True + intercept_events: True + invisible_layout: False + layout_controller: None + layout_needed: False + legend: + legend_alignment: 'ur' + orientation: 'h' + origin: 'bottom left' + outer_bounds: (800, 600) + outer_height: 600 + outer_position: (0, 0) + outer_width: 800 + outer_x: 0 + outer_x2: 799 + outer_y: 0 + outer_y2: 599 + overlay_border: True + overlays: [] + padding: [50, 50, 50, 50] + padding_accepts_focus: True + padding_bottom: 50 + padding_left: 50 + padding_right: 50 + padding_top: 50 + parent: None + plot_components: [] + plots: {'plot0': []} + pointer: 'arrow' + position: [50, 50] + range2d: + renderer_map: {'bar': } + resizable: 'hv' + resolver: None + title: '' + title_angle: 0 + title_color: 'black' + title_font: Font(size=16,family=1,weig... face_name='',encoding=0 ) + title_position: 'top' + title_text: '' + tools: [] + tooltip: None + underlays: [] + unified_draw: False + use_backbuffer: False + use_draw_order: True + use_selection: False + value_axis: + value_grid: + value_mapper: + value_range: + value_scale: 'linear' + viewports: [] + visible: True + vpadding: 100 + width: 700 + window: None + x: 50 + x2: 749 + x_axis: + x_grid: + x_mapper: + y: 50 + y2: 549 + y_axis: + y_grid: + y_mapper: + +.. index: + pair: ArrayPlotData; print_traits() + +Introspecting into ``tp.myTP.data`` produces:: + + tp.myTP.data + + + tp.myTP.data.print_traits() + arrays: {'Y': array([ 4.57391553e-19, ...923, 6.15625227, 6.28318531])} + selectable: True + writable: True + + tp.myTP.data.__dict__ + {'arrays': + { 'Y': array([ + 4.57391553e-19, 2.68399330e-04, 6.04546385e-04, + 1.01572218e-03, 1.50856699e-03, 2.08865225e-03, + 2.75996780e-03, 3.52431888e-03, 4.38062872e-03, + 5.32414502e-03, 6.34555158e-03, 7.42999022e-03, + 8.55600270e-03, 9.69440840e-03, 1.08071401e-02, + 1.18460684e-02, 1.27518549e-02, 1.34528831e-02, + 1.38643309e-02, 1.38874568e-02, 1.34091901e-02, + 1.23021262e-02, 1.04250455e-02, 7.62408714e-03, + 3.73472511e-03, -1.41529513e-03, -8.00188797e-03, + -1.61992496e-02, -2.61729883e-02, -3.80715840e-02, + -5.20160056e-02, -6.80873351e-02, -8.63122735e-02, + -1.06646448e-01, -1.28955496e-01, -1.52993971e-01, + -1.78382224e-01, -2.04581503e-01, -2.30867687e-01, + -2.56304206e-01, -2.79714905e-01, -2.99657838e-01, + -3.14401207e-01, -3.21902952e-01, -3.19795797e-01, + -3.05379868e-01, -2.75625351e-01, -2.27187982e-01, + -1.56440526e-01, -5.95237001e-02, 5.95237001e-02, + 1.56440526e-01, 2.27187982e-01, 2.75625351e-01, + 3.05379868e-01, 3.19795797e-01, 3.21902952e-01, + 3.14401207e-01, 2.99657838e-01, 2.79714905e-01, + 2.56304206e-01, 2.30867687e-01, 2.04581503e-01, + 1.78382224e-01, 1.52993971e-01, 1.28955496e-01, + 1.06646448e-01, 8.63122735e-02, 6.80873351e-02, + 5.20160056e-02, 3.80715840e-02, 2.61729883e-02, + 1.61992496e-02, 8.00188797e-03, 1.41529513e-03, + -3.73472511e-03, -7.62408714e-03, -1.04250455e-02, + -1.23021262e-02, -1.34091901e-02, -1.38874568e-02, + -1.38643309e-02, -1.34528831e-02, -1.27518549e-02, + -1.18460684e-02, -1.08071401e-02, -9.69440840e-03, + -8.55600270e-03, -7.42999022e-03, -6.34555158e-03, + -5.32414502e-03, -4.38062872e-03, -3.52431888e-03, + -2.75996780e-03, -2.08865225e-03, -1.50856699e-03, + -1.01572218e-03, -6.04546385e-04, -2.68399330e-04, + -4.57391553e-19]), + 'X': array([ + -6.28318531, -6.15625227, -6.02931923, -5.9023862 , -5.77545316, + -5.64852012, -5.52158709, -5.39465405, -5.26772102, -5.14078798, + -5.01385494, -4.88692191, -4.75998887, -4.63305583, -4.5061228 , + -4.37918976, -4.25225672, -4.12532369, -3.99839065, -3.87145761, + -3.74452458, -3.61759154, -3.4906585 , -3.36372547, -3.23679243, + -3.10985939, -2.98292636, -2.85599332, -2.72906028, -2.60212725, + -2.47519421, -2.34826118, -2.22132814, -2.0943951 , -1.96746207, + -1.84052903, -1.71359599, -1.58666296, -1.45972992, -1.33279688, + -1.20586385, -1.07893081, -0.95199777, -0.82506474, -0.6981317 , + -0.57119866, -0.44426563, -0.31733259, -0.19039955, -0.06346652, + 0.06346652, 0.19039955, 0.31733259, 0.44426563, 0.57119866, + 0.6981317 , 0.82506474, 0.95199777, 1.07893081, 1.20586385, + 1.33279688, 1.45972992, 1.58666296, 1.71359599, 1.84052903, + 1.96746207, 2.0943951 , 2.22132814, 2.34826118, 2.47519421, + 2.60212725, 2.72906028, 2.85599332, 2.98292636, 3.10985939, + 3.23679243, 3.36372547, 3.4906585 , 3.61759154, 3.74452458, + 3.87145761, 3.99839065, 4.12532369, 4.25225672, 4.37918976, + 4.5061228 , 4.63305583, 4.75998887, 4.88692191, 5.01385494, + 5.14078798, 5.26772102, 5.39465405, 5.52158709, 5.64852012, + 5.77545316, 5.9023862 , 6.02931923, 6.15625227, 6.28318531])}, + 'writable': True} + +.. index: + pair: ArrayDataSource; print_traits() + +The ArrayDataSource objects describes a single, continuous array of +numerical data. The object contains the raw data (without a useful label) +along with some descriptors about the array:: + + tp.myTP.datasources['X'] + + + tp.myTP.datasources['X'].print_traits() + _cached_bounds: (-6.2831853071795862, 6.2831853071795862) + _cached_mask: None + _data: array([-6.28318531, -6.1562522...3, 6.15625227, 6.28318531]) + _max_index: 99 + _min_index: 0 + index_dimension: 'scalar' + metadata: {'annotations': [], 'selections': []} + persist_data: True + sort_order: 'none' + value_dimension: 'scalar' + + tp.myTP.datasources['X'].__dict__ + { + '_max_index': 99, + '_cached_bounds': (-6.2831853071795862, 6.2831853071795862), + '_data': + array([-6.28318531, -6.15625227, -6.02931923, -5.9023862 , -5.77545316, + -5.64852012, -5.52158709, -5.39465405, -5.26772102, -5.14078798, + -5.01385494, -4.88692191, -4.75998887, -4.63305583, -4.5061228 , + -4.37918976, -4.25225672, -4.12532369, -3.99839065, -3.87145761, + -3.74452458, -3.61759154, -3.4906585 , -3.36372547, -3.23679243, + -3.10985939, -2.98292636, -2.85599332, -2.72906028, -2.60212725, + -2.47519421, -2.34826118, -2.22132814, -2.0943951 , -1.96746207, + -1.84052903, -1.71359599, -1.58666296, -1.45972992, -1.33279688, + -1.20586385, -1.07893081, -0.95199777, -0.82506474, -0.6981317 , + -0.57119866, -0.44426563, -0.31733259, -0.19039955, -0.06346652, + 0.06346652, 0.19039955, 0.31733259, 0.44426563, 0.57119866, + 0.6981317 , 0.82506474, 0.95199777, 1.07893081, 1.20586385, + 1.33279688, 1.45972992, 1.58666296, 1.71359599, 1.84052903, + 1.96746207, 2.0943951 , 2.22132814, 2.34826118, 2.47519421, + 2.60212725, 2.72906028, 2.85599332, 2.98292636, 3.10985939, + 3.23679243, 3.36372547, 3.4906585 , 3.61759154, 3.74452458, + 3.87145761, 3.99839065, 4.12532369, 4.25225672, 4.37918976, + 4.5061228 , 4.63305583, 4.75998887, 4.88692191, 5.01385494, + 5.14078798, 5.26772102, 5.39465405, 5.52158709, 5.64852012, + 5.77545316, 5.9023862 , 6.02931923, 6.15625227, 6.28318531]), + 'sort_order': 'none', + '_min_index': 0 + } + +.. index: + pair: PlotGrid; print_traits() + +Let's examine the plot grids. +:: + + tp.myTP.x_grid + + + tp.myTP.x_grid.print_traits() + _active_tool: None + _backbuffer: None + _cache_valid: False + _layout_needed: True + _tick_extents: array([[ 50., 510.],\n ...,\n [ 50., 510.]]) + _tick_list: None + _tick_positions: array([[ 120., 50.],\n ...,\n [ 661., 50.]]) + _window: None + accepts_focus: True + active_tool: None + aspect_ratio: None + auto_center: True + auto_handle_event: False + backbuffer_padding: True + bgcolor: 'none' + bgcolor_: (0.0, 0.0, 0.0, 0.0) + border_color: 'black' + border_dash: 'solid' + border_visible: False + border_width: 1 + bounds: [682, 460] + classes: [] + component: + container: None + controller: None + cursor_color: 'black' + cursor_style: 'default' + data_max: None + data_min: None + draw_layer: 'overlay' + draw_order: ['background', 'image', 'un..., 'annotation', 'overlay'] + draw_valid: False + drawn_outer_bounds: [0.0, 0.0] + drawn_outer_position: [0.0, 0.0] + event_state: 'normal' + fill_padding: False + fixed_preferred_size: None + flip_axis: False + grid_interval: 'auto' + height: 460 + hpadding: 0 + id: '' + inset_border: True + invisible_layout: False + layout_needed: True + line_color: 'lightgray' + line_color_: (0.827, 0.827, 0.827, 1.0) + line_style: 'dot' + line_style_: array([ 2., 2.]) + line_weight: 1 + line_width: 1 + mapper: + orientation: 'vertical' + outer_bounds: (682, 460) + outer_height: 460 + outer_position: (50, 50) + outer_width: 682 + outer_x: 50 + outer_x2: 731 + outer_y: 50 + outer_y2: 509 + overlay_border: True + overlays: [] + padding: [0, 0, 0, 0] + padding_accepts_focus: True + padding_bottom: 0 + padding_left: 0 + padding_right: 0 + padding_top: 0 + pointer: 'arrow' + position: [50, 50] + resizable: 'hv' + tick_generator: + tools: [] + tooltip: None + transverse_bounds: None + transverse_mapper: None + underlays: [] + unified_draw: False + use_backbuffer: False + use_draw_order: True + use_selection: False + viewports: [] + visible: True + vpadding: 0 + width: 682 + window: None + x: 50 + x2: 731 + y: 50 + y2: 509 + +.. index: + pair: PlotAxis; print_traits() + +Axes +:: + + tp.myTP.x_axis + + + tp.myTP.x_axis.print_traits() + _active_tool: None + _axis_pixel_vector: array([ 1., 0.]) + _axis_vector: array([ 681., 0.]) + _backbuffer: None + _cache_valid: True + _end_axis_point: array([ 731., 50.]) + _inside_vector: array([ 0., 1.]) + _layout_needed: False + _major_axis: array([ 1., 0.]) + _major_axis_size: 682.0 + _minor_axis_size: 460.0 + _origin_point: array([50, 50]) + _tick_label_bounding_boxes: [array([ 14., 12.]), ar...]), array([ 10., 12.])] + _tick_label_list: array([-5. , -2.5, 0. , 2.5, 5. ]) + _tick_label_positions: array([[ 120., 50.],\n...n [ 661., 50.]]) + _tick_list: [] + _tick_positions: array([[ 120., 50.],\n...n [ 661., 50.]]) + _title_angle: 0.0 + _title_orientation: array([ 0., 1.]) + _window: None + accepts_focus: True + active_tool: None + aspect_ratio: None + auto_center: True + auto_handle_event: False + axis_line_color: 'black' + axis_line_color_: (0.0, 0.0, 0.0, 1.0) + axis_line_style: 'solid' + axis_line_style_: None + axis_line_visible: True + axis_line_weight: 1.0 + backbuffer_padding: True + bgcolor: 'transparent' + border_color: 'black' + border_dash: 'solid' + border_visible: False + border_width: 1 + bounds: [682, 50] + classes: [] + component: + container: None + controller: None + cursor_color: 'black' + cursor_style: 'default' + draw_layer: 'overlay' + draw_order: ['background', 'image', ...'annotation', 'overlay'] + draw_valid: False + drawn_outer_bounds: [0.0, 0.0] + drawn_outer_position: [0.0, 0.0] + ensure_labels_bounded: False + ensure_ticks_bounded: False + event_state: 'normal' + fill_padding: False + fixed_preferred_size: None + height: 50 + hpadding: 0 + id: '' + inset_border: True + invisible_layout: False + layout_needed: False + mapper: + orientation: 'bottom' + outer_bounds: (682, 50) + outer_height: 50 + outer_position: (50, 0) + outer_width: 682 + outer_x: 50 + outer_x2: 731 + outer_y: 0 + outer_y2: 49 + overlay_border: True + overlays: [] + padding: [0, 0, 0, 0] + padding_accepts_focus: True + padding_bottom: 0 + padding_left: 0 + padding_right: 0 + padding_top: 0 + pointer: 'arrow' + position: [50, 0] + resizable: 'hv' + small_haxis_style: False + tick_color: 'black' + tick_color_: (0.0, 0.0, 0.0, 1.0) + tick_generator: + tick_in: 5 + tick_interval: 'auto' + tick_label_alignment: 'edge' + tick_label_color: 'black' + tick_label_font: Font(size=10,family=3,we...ace_name='',encoding=0 ) + tick_label_formatter: + tick_label_margin: 2 + tick_label_offset: 8.0 + tick_label_position: 'outside' + tick_label_rotate_angle: 0 + tick_out: 5 + tick_visible: True + tick_weight: 1.0 + ticklabel_cache: [] + title: '' + title_angle: 0.0 + title_color: 'black' + title_font: Font(size=12,family=3,we...ace_name='',encoding=0 ) + title_spacing: 'auto' + tools: [] + tooltip: None + underlays: [] + unified_draw: False + use_backbuffer: False + use_draw_order: True + use_selection: False + viewports: [] + visible: True + vpadding: 0 + width: 682 + window: None + x: 50 + x2: 731 + y: 0 + y2: 49 + +.. index: + pair: DataRange2D; print_traits() + pair: DataRange1D; print_traits() + +Plotting Ranges +:: + + tp.myTP.range2d.print_traits() + _high_setting: ('auto', 'auto') + _high_value: (inf, inf) + _low_setting: ('auto', 'auto') + _low_value: (-inf, -inf) + _xrange: + _yrange: + epsilon: (0.0001, 0.0001) + high: (6.283185307179586, 0.32190295210375436) + high_setting: ('auto', 'auto') + low: (-6.283185307179586, -0.3219029521037544) + low_setting: ('auto', 'auto') + sources: [] + tight_bounds: (True, True) + x_range: + y_range: + +The ``range2d`` attribute contains both an ``x_range`` and a ``y_range`` object. +Let's look at the ``x_range`` object:: + + tp.myTP.range2d.x_range + + + tp.myTP.range2d.x_range.print_traits() + _high_setting: 'auto' + _high_value: 6.2831853071795862 + _low_setting: 'auto' + _low_value: -6.2831853071795862 + bounds_func: None + default_state: 'auto' + default_tracking_amount: 20.0 + epsilon: 1e-10 + fit_to_subset: False + high: 6.283185307179586 + high_setting: 'auto' + low: -6.283185307179586 + low_setting: 'auto' + margin: 0.05 + sources: [] + tight_bounds: True + tracking_amount: 20.0 diff --git a/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_01.png b/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_01.png new file mode 100644 index 000000000..f85fdcfac Binary files /dev/null and b/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_01.png differ diff --git a/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_01.py b/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_01.py new file mode 100644 index 000000000..02f87076d --- /dev/null +++ b/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_01.py @@ -0,0 +1,67 @@ +## ex_chaco_line_01.py + +# standard imports +import os, inspect +import numpy as np + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + # generate interesting data + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + # map arrays to plot names. TADP suffix => Traits ArrayPlotData + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + # generate the plot. TP suffix => Traits Plot + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # generate the view + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + # generate and display the plot + tp = TraitedPlot() + tp.configure_traits() + + # after we close the plot, all the attributes of the plot will be set (see + # Lazy Initialization). Introspect into the tp object + + # generate a list of the public attributes in the Traits Plot objext + myPublics = [thisItem for thisItem in inspect.getmembers(tp.myTP) if thisItem[0][0] != '_'] + print( myPublics ) + + # use the print_traits() method to show a subset of the plot attributes + tp.myTP.print_traits() diff --git a/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_02.py b/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_02.py new file mode 100644 index 000000000..6b1aad46b --- /dev/null +++ b/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_02.py @@ -0,0 +1,87 @@ +## ex_chaco_line_01.py + +# standard imports +import inspect +import numpy as np + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +class TraitedPlot( HasTraits ): + '''simple line plot''' + + # generate interesting data + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + # map names to data. TADP postfix => Traits ArrayPlotData + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + # generate the plot. TP postfix => Traits Plot + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # generate the view + mySize = (800,600) + myTitle = 'myPlot' + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = mySize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = myTitle, + width = mySize[0], height = mySize[1], + ) + +if __name__ == "__main__": + + # generate and display the plot + tp = TraitedPlot() + tp.configure_traits() + + # after we close the plot, all the attributes of the plot have been guarenteed + # to be set (see Lazy Initialization). Introspect into the tp object + + # generate a list of the public attributes in the Traits Plot objext + myPublics = [thisItem for thisItem in inspect.getmembers(tp.myTP) if thisItem[0][0] != '_'] + print( myPublics ) + + # use the print_traits() method to show a subset of the plot attributes + tp.myTP.print_traits() + + # the data + tp.myTP.data.print_traits() + tp.myTP.datasources['X'].print_traits() + tp.myTP.datasources['Y'].print_traits() + + # padding + tp.myTP.padding + tp.myTP.padding_left + tp.myTP.padding_right + tp.myTP.padding_bottom + tp.myTP.padding_top + + # grids + tp.myTP.x_grid.print_traits() + + # axes + tp.myTP.x_axis.print_traits() + + # plotting ranges + tp.myTP.range2d.print_traits() + tp.myTP.range2d.x_range.print_traits() diff --git a/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_0foo.py b/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_0foo.py new file mode 100644 index 000000000..6b1aad46b --- /dev/null +++ b/docs/FAQ/source/elementsChacoLinePlot/ex_chaco_line_0foo.py @@ -0,0 +1,87 @@ +## ex_chaco_line_01.py + +# standard imports +import inspect +import numpy as np + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +class TraitedPlot( HasTraits ): + '''simple line plot''' + + # generate interesting data + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + # map names to data. TADP postfix => Traits ArrayPlotData + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + # generate the plot. TP postfix => Traits Plot + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # generate the view + mySize = (800,600) + myTitle = 'myPlot' + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = mySize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = myTitle, + width = mySize[0], height = mySize[1], + ) + +if __name__ == "__main__": + + # generate and display the plot + tp = TraitedPlot() + tp.configure_traits() + + # after we close the plot, all the attributes of the plot have been guarenteed + # to be set (see Lazy Initialization). Introspect into the tp object + + # generate a list of the public attributes in the Traits Plot objext + myPublics = [thisItem for thisItem in inspect.getmembers(tp.myTP) if thisItem[0][0] != '_'] + print( myPublics ) + + # use the print_traits() method to show a subset of the plot attributes + tp.myTP.print_traits() + + # the data + tp.myTP.data.print_traits() + tp.myTP.datasources['X'].print_traits() + tp.myTP.datasources['Y'].print_traits() + + # padding + tp.myTP.padding + tp.myTP.padding_left + tp.myTP.padding_right + tp.myTP.padding_bottom + tp.myTP.padding_top + + # grids + tp.myTP.x_grid.print_traits() + + # axes + tp.myTP.x_axis.print_traits() + + # plotting ranges + tp.myTP.range2d.print_traits() + tp.myTP.range2d.x_range.print_traits() diff --git a/docs/FAQ/source/index.rst b/docs/FAQ/source/index.rst new file mode 100644 index 000000000..ff3c92f0f --- /dev/null +++ b/docs/FAQ/source/index.rst @@ -0,0 +1,26 @@ +Chaco FAQ +========= + +This is the Frequently Asked Questions list for Chaco. There is some overlap +between Traits, TraitsUI and Chaco so take a look at the FAQs under those topics +as well. + +.. toctree:: + :maxdepth: 2 + + elementsChacoLinePlot/elementsChacoLinePlot.rst + myTP.title/myTP.title.rst + myTP.range/myTP.range.rst + myTP.grid/myTP.grid.rst + myTP.axes/myTP.axes.rst + myTP.plotlabel/myTP.plotlabel.rst + colorbar/colorbar.rst + colormapper/colormapper.rst + cheatSheet/cheatSheet.rst + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/FAQ/source/myTP.axes/ex_chaco_myTP.axes_01.py b/docs/FAQ/source/myTP.axes/ex_chaco_myTP.axes_01.py new file mode 100644 index 000000000..263f26983 --- /dev/null +++ b/docs/FAQ/source/myTP.axes/ex_chaco_myTP.axes_01.py @@ -0,0 +1,126 @@ +## ex_chaco_myTP.axes_01.py + +# standard imports +import inspect, os +import numpy as np + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # Define the axis label. title is a string or unicode object that is rendered + # using the given font and color. title_font is a string describing a font + # (e.g. '12 pt bold italic', 'swiss family Arial' or 'default 12'; see + # TraitKivaFont for details). Finally, title_spacing is the space between the + # axis line and the title (either the number of pixels or 'auto', default). + myTP.x_axis.title = 'My X-Axis Title' + myTP.x_axis.title_font = 'modern 20' + myTP.x_axis.title_color = 'red' + myTP.x_axis.title_spacing = 'auto' + + # These attributes control the aspect of the ticks on the axis. If + # tick_visible is True, ticks are represented as lines of color tick_color + # (default is black) and thickness tick_weight (in pixels, default is 1). Each + # line extends into the plot area by tick_in pixels and into the label area by + # tick_out pixels (default is 5). + myTP.x_axis.tick_weight + myTP.x_axis.tick_color + myTP.x_axis.tick_in + myTP.x_axis.tick_out + myTP.x_axis.tick_visible = True + + # The attributes allow the user to fine-tune the aspect of the tick labels: + # first of all, the font (e.g. '12 pt bold italic') and color of the labels. + # The position and orientation of the label can be also be closely controlled: + # tick_label_rotate_angle give the rotation angle (only multiples of 90 + # degrees are supported); tick_label_alignment selects whether the corner + # ('corner') or center ('edge', default) of the label are aligned to the + # corresponding tick ('corner' is better for 45 degrees rotation); + # tick_label_margin and tick_label_offset control the margin around the tick + # labels, and their distance from the axis; finally, tick_label_position can + # be set to either 'outside' (default) or 'inside' depending on whether the + # labels should be displayed inside or outside the plot area. + myTP.x_axis.tick_label_font = 'modern 16' + myTP.x_axis.tick_label_color + myTP.x_axis.tick_label_rotate_angle + myTP.x_axis.tick_label_alignment + myTP.x_axis.tick_label_margin + myTP.x_axis.tick_label_offset + myTP.x_axis.tick_label_position + + # By default, tick labels are assumed to be floating point numbers, and are + # displayed as such after removing trailing zeros and the decimal dot if + # necessary (e.g., '10.000' will be displayed as '10', and '21.10' as '21.1'). + # The default behavior can be changed by setting tick_label_formatter to a + # callable that takes the value of the tick label and returns a formatted + # string. + myTP.x_axis.tick_label_formatter + + # Locations and distances of ticks are controlled by the attribute + # tick_generator. Default is chaco.ticks.auto_ticks or + # chaco.ticks.log_auto_ticks + myTP.x_axis.tick_interval # 'auto' + myTP.x_axis.tick_generator + + # Orientation of the axis. Can put it on the top or bottom. + # left or right available, but not useful + myTP.x_axis.orientation = 'bottom' + + # axis line + myTP.x_axis.axis_line_weight # 2 + myTP.x_axis.axis_line_color # 'black' + myTP.x_axis.axis_line_color_ # (0.0, 0.0, 0.0, 1.0) + myTP.x_axis.axis_line_style # 'solid' + myTP.x_axis.axis_line_style_ # None + myTP.x_axis.axis_line_visible # True or False + + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + print( tp.myTP.x_axis ) + + myMethods = inspect.getmembers(tp.myTP.x_axis) + myPublics = [thisItem for thisItem in myMethods if thisItem[0][0] != '_'] + print( myPublics ) + + tp.myTP.x_axis.print_traits() diff --git a/docs/FAQ/source/myTP.axes/ex_chaco_myTP.axes_02.py b/docs/FAQ/source/myTP.axes/ex_chaco_myTP.axes_02.py new file mode 100644 index 000000000..79ad88351 --- /dev/null +++ b/docs/FAQ/source/myTP.axes/ex_chaco_myTP.axes_02.py @@ -0,0 +1,134 @@ +## ex_chaco_myTP.axes_02.py + +""" +Simple plot, with axes options +""" + +## -- Notes ----------------------------------------------------------------- + +## -- Imports --------------------------------------------------------------- +# standard imports +import inspect +import numpy as np + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +## -- Let's Begin ----------------------------------------------------------- + +## -- Classes --------------------------------------------------------------- + +class MyPlot( HasTraits ): + '''simple line plot''' + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # Define the axis label. title is a string or unicode object that is rendered + # using the given font and color. title_font is a string describing a font + # (e.g. '12 pt bold italic', 'swiss family Arial' or 'default 12'; see + # TraitKivaFont for details). Finally, title_spacing is the space between the + # axis line and the title (either the number of pixels or 'auto', default). + myTP.x_axis.title = 'My X-Axis Title' + myTP.x_axis.title_font = 'modern 20' + myTP.x_axis.title_color = 'red' + myTP.x_axis.title_spacing = 'auto' + + # These attributes control the aspect of the ticks on the axis. If + # tick_visible is True, ticks are represented as lines of color tick_color + # (default is black) and thickness tick_weight (in pixels, default is 1). Each + # line extends into the plot area by tick_in pixels and into the label area by + # tick_out pixels (default is 5). + myTP.x_axis.tick_weight + myTP.x_axis.tick_color + myTP.x_axis.tick_in + myTP.x_axis.tick_out + myTP.x_axis.tick_visible = True + + # The attributes allow the user to fine-tune the aspect of the tick labels: + # first of all, the font (e.g. '12 pt bold italic') and color of the labels. + # The position and orientation of the label can be also be closely controlled: + # tick_label_rotate_angle give the rotation angle (only multiples of 90 + # degrees are supported); tick_label_alignment selects whether the corner + # ('corner') or center ('edge', default) of the label are aligned to the + # corresponding tick ('corner' is better for 45 degrees rotation); + # tick_label_margin and tick_label_offset control the margin around the tick + # labels, and their distance from the axis; finally, tick_label_position can + # be set to either 'outside' (default) or 'inside' depending on whether the + # labels should be displayed inside or outside the plot area. + myTP.x_axis.tick_label_font = 'modern 16' + myTP.x_axis.tick_label_color + myTP.x_axis.tick_label_rotate_angle + myTP.x_axis.tick_label_alignment + myTP.x_axis.tick_label_margin + myTP.x_axis.tick_label_offset + myTP.x_axis.tick_label_position + + # By default, tick labels are assumed to be floating point numbers, and are + # displayed as such after removing trailing zeros and the decimal dot if + # necessary (e.g., '10.000' will be displayed as '10', and '21.10' as '21.1'). + # The default behavior can be changed by setting tick_label_formatter to a + # callable that takes the value of the tick label and returns a formatted + # string. + myTP.x_axis.tick_label_formatter + + # Locations and distances of ticks are controlled by the attribute + # tick_generator. Default is chaco.ticks.auto_ticks or + # chaco.ticks.log_auto_ticks + myTP.x_axis.tick_interval # 'auto' + myTP.x_axis.tick_generator + + # Orientation of the axis. Can put it on the top or bottom. + # left or right available, but not useful + myTP.x_axis.orientation = 'bottom' + + # axis line + myTP.x_axis.axis_line_weight # 2 + myTP.x_axis.axis_line_color # 'black' + myTP.x_axis.axis_line_color_ # (0.0, 0.0, 0.0, 1.0) + myTP.x_axis.axis_line_style # 'solid' + myTP.x_axis.axis_line_style_ # None + myTP.x_axis.axis_line_visible # True or False + + + mySize = (800,600) + myTitle = 'myPlot' + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = mySize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = myTitle, + width = mySize[0], height = mySize[1], + ) + +## -- Functions ------------------------------------------------------------- + +## -- Main ------------------------------------------------------------------ + +if __name__ == "__main__": + + myPlot = MyPlot() + myPlot.configure_traits() + +## -- EOF ------------------------------------------------------------------- diff --git a/docs/FAQ/source/myTP.axes/myTP.axes.rst b/docs/FAQ/source/myTP.axes/myTP.axes.rst new file mode 100644 index 000000000..197d484ab --- /dev/null +++ b/docs/FAQ/source/myTP.axes/myTP.axes.rst @@ -0,0 +1,413 @@ +Chaco Plot - Axes Options +========================= + +.. highlight:: python + :linenothreshold: 5 + +.. index:: Axes + +Let's generate a Chaco plot, and output attributes associated with the +axes labelling, tick marks, etc. We'll concentrate on the x-axis but, of course, +the material applies to the y-axis as well. +:: + + ## ex_chaco_myTP.axes_01.py + + # standard imports + import inspect, os + import numpy as np + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import Plot, ArrayPlotData + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # Define the axis label. title is a string or unicode object that is rendered + # using the given font and color. title_font is a string describing a font + # (e.g. '12 pt bold italic', 'swiss family Arial' or 'default 12'; see + # TraitKivaFont for details). Finally, title_spacing is the space between the + # axis line and the title (either the number of pixels or 'auto', default). + myTP.x_axis.title = 'My X-Axis Title' + myTP.x_axis.title_font = 'modern 20' + myTP.x_axis.title_color = 'red' + myTP.x_axis.title_spacing = 'auto' + + # These attributes control the aspect of the ticks on the axis. If + # tick_visible is True, ticks are represented as lines of color tick_color + # (default is black) and thickness tick_weight (in pixels, default is 1). Each + # line extends into the plot area by tick_in pixels and into the label area by + # tick_out pixels (default is 5). + myTP.x_axis.tick_weight + myTP.x_axis.tick_color + myTP.x_axis.tick_in + myTP.x_axis.tick_out + myTP.x_axis.tick_visible = True + + # The attributes allow the user to fine-tune the aspect of the tick labels: + # first of all, the font (e.g. '12 pt bold italic') and color of the labels. + # The position and orientation of the label can be also be closely controlled: + # tick_label_rotate_angle give the rotation angle (only multiples of 90 + # degrees are supported); tick_label_alignment selects whether the corner + # ('corner') or center ('edge', default) of the label are aligned to the + # corresponding tick ('corner' is better for 45 degrees rotation); + # tick_label_margin and tick_label_offset control the margin around the tick + # labels, and their distance from the axis; finally, tick_label_position can + # be set to either 'outside' (default) or 'inside' depending on whether the + # labels should be displayed inside or outside the plot area. + myTP.x_axis.tick_label_font = 'modern 16' + myTP.x_axis.tick_label_color + myTP.x_axis.tick_label_rotate_angle + myTP.x_axis.tick_label_alignment + myTP.x_axis.tick_label_margin + myTP.x_axis.tick_label_offset + myTP.x_axis.tick_label_position + + # By default, tick labels are assumed to be floating point numbers, and are + # displayed as such after removing trailing zeros and the decimal dot if + # necessary (e.g., '10.000' will be displayed as '10', and '21.10' as '21.1'). + # The default behavior can be changed by setting tick_label_formatter to a + # callable that takes the value of the tick label and returns a formatted + # string. + myTP.x_axis.tick_label_formatter + + # Locations and distances of ticks are controlled by the attribute + # tick_generator. Default is chaco.ticks.auto_ticks or + # chaco.ticks.log_auto_ticks + myTP.x_axis.tick_interval # 'auto' + myTP.x_axis.tick_generator + + # Orientation of the axis. Can put it on the top or bottom. + # left or right available, but not useful + myTP.x_axis.orientation = 'bottom' + + # axis line + myTP.x_axis.axis_line_weight # 2 + myTP.x_axis.axis_line_color # 'black' + myTP.x_axis.axis_line_color_ # (0.0, 0.0, 0.0, 1.0) + myTP.x_axis.axis_line_style # 'solid' + myTP.x_axis.axis_line_style_ # None + myTP.x_axis.axis_line_visible # True or False + + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + print( tp.myTP.x_axis ) + + myMethods = inspect.getmembers(tp.myTP.x_axis) + myPublics = [thisItem for thisItem in myMethods if thisItem[0][0] != '_'] + print( myPublics ) + + tp.myTP.x_axis.print_traits() + +The reader is encouraged to examine the outputs of the ``print( +myPlot.myTP.x_axis )``, the ``print( myPublics )`` and the +``tp.myTP.x_axis.print_traits()`` line for insight into the behavior of the +plot title. The data is also available under the Excruciating Detail heading +below. + +Excruciating Detail +------------------- + +.. index: + pair: PlotAxis; print_traits() + +The output of the ``print( myPlot.myTP.x_axis )`` call is:: + + + +The output from the ``print( myPublics )`` call is:: + + [ + ('add_class_trait', >), + ('add_trait', >), + ('add_trait_category', >), + ('add_trait_listener', >), + ('all_trait_names', >), + ('as_coordinates', >), + ('aspect_ratio', None), + ('axis_line_color', 'black'), + ('axis_line_color_', (0.0, 0.0, 0.0, 1.0)), + ('axis_line_style', 'solid'), + ('axis_line_style_', None), + ('axis_line_visible', True), + ('axis_line_weight', 1.0), + ('base_trait', >), + ('border_visible', False), + ('bounds', [700, 50]), + ('class_default_traits_view', >), + ('class_editable_traits', >), + ('class_trait_names', >), + ('class_trait_view', >), + ('class_trait_view_elements', >), + ('class_traits', >), + ('cleanup', >), + ('clone_traits', >), + ('component', ), + ('configure_traits', >), + ('container', None), + ('copy_traits', >), + ('copyable_trait_names', >), + ('default_traits_view', >), + ('dispatch', >), + ('do_layout', >), + ('draw', >), + ('draw_select_box', >), + ('draw_valid', False), + ('drawn_outer_bounds', [0.0, 0.0]), + ('drawn_outer_position', [0.0, 0.0]), + ('edit_traits', >), + ('editable_traits', >), + ('ensure_labels_bounded', False), + ('ensure_ticks_bounded', False), + ('get', >), + ('get_absolute_coords', >), + ('get_event_transform', >), + ('get_preferred_size', >), + ('has_traits_interface', >), + ('invalidate', >), + ('invalidate_and_redraw', >), + ('invalidate_draw', >), + ('is_in', >), + ('mapper', ), + ('mapper_updated', >), + ('on_trait_change', >), + ('on_trait_event', >), + ('orientation', 'bottom'), + ('overlay', >), + ('overlays', []), + ('padding_bottom', 0), + ('padding_left', 0), + ('padding_right', 0), + ('padding_top', 0), + ('position', [50, 0]), + ('print_traits', >), + ('remove_trait', >), + ('remove_trait_listener', >), + ('request_redraw', >), + ('reset_traits', >), + ('set', >), + ('set_outer_bounds', >), + ('set_outer_position', >), + ('set_trait_dispatch_handler', >), + ('small_haxis_style', False), + ('sync_trait', >), + ('tick_color', 'black'), + ('tick_color_', (0.0, 0.0, 0.0, 1.0)), + ('tick_generator', ), + ('tick_in', 5), + ('tick_interval', 'auto'), + ('tick_label_alignment', 'edge'), + ('tick_label_color', 'black'), + ('tick_label_font', Font(size=16,family=3,weight=0, style=0, face_name='',encoding=0 )), + ('tick_label_formatter', ), + ('tick_label_margin', 2), + ('tick_label_offset', 8.0), + ('tick_label_position', 'outside'), + ('tick_label_rotate_angle', 0), + ('tick_out', 5), + ('tick_visible', True), + ('tick_weight', 1.0), + ('ticklabel_cache', + [ , + , + , + , + ]), + ('title', 'My X-Axis Title'), + ('title_angle', 0.0), + ('title_color', 'red'), + ('title_color_', (1.0, 0.0, 0.0, 1.0)), + ('title_font', Font(size=20,family=3,weight=0, style=0, face_name='',encoding=0 )), + ('title_spacing', 'auto'), + ('trait', >), + ('trait_context', >), + ('trait_get', >), + ('trait_items_event', ), + ('trait_monitor', >), + ('trait_names', >), + ('trait_property_changed', ), + ('trait_set', >), + ('trait_setq', >), + ('trait_subclasses', >), + ('trait_view', >), + ('trait_view_elements', >), + ('trait_views', >), + ('traits', >), + ('traits_init', ), + ('traits_inited', ), + ('traits_view', >), + ('underlays', []), + ('use_draw_order', True), + ('validate_trait', >), + ('viewports', []), + ('visible', True), + ('wrappers', + { 'new': , + 'ui': , + 'extended': , + 'fast_ui': , + 'same': }) + ] + +The output from the ``tp.myTP.x_axis.print_traits()`` call is:: + + _active_tool: None + _axis_pixel_vector: array([ 1., 0.]) + _axis_vector: array([ 699., 0.]) + _backbuffer: None + _cache_valid: True + _end_axis_point: array([ 749., 50.]) + _inside_vector: array([ 0., 1.]) + _layout_needed: False + _major_axis: array([ 1., 0.]) + _major_axis_size: 700.0 + _minor_axis_size: 500.0 + _origin_point: array([50, 50]) + _tick_label_bounding_boxes: [array([ 20., 16.]), ar...]), array([ 14., 16.])] + _tick_label_list: array([-5. , -2.5, 0. , 2.5, 5. ]) + _tick_label_positions: array([[ 121., 50.],\n...n [ 678., 50.]]) + _tick_list: [] + _tick_positions: array([[ 121., 50.],\n...n [ 678., 50.]]) + _title_angle: 0.0 + _title_orientation: array([ 0., 1.]) + _window: None + accepts_focus: True + active_tool: None + aspect_ratio: None + auto_center: True + auto_handle_event: False + axis_line_color: 'black' + axis_line_color_: (0.0, 0.0, 0.0, 1.0) + axis_line_style: 'solid' + axis_line_style_: None + axis_line_visible: True + axis_line_weight: 1.0 + backbuffer_padding: True + bgcolor: 'transparent' + border_color: 'black' + border_dash: 'solid' + border_visible: False + border_width: 1 + bounds: [700, 50] + classes: [] + component: + container: None + controller: None + cursor_color: 'black' + cursor_style: 'default' + draw_layer: 'overlay' + draw_order: ['background', 'image', ...'annotation', 'overlay'] + draw_valid: False + drawn_outer_bounds: [0.0, 0.0] + drawn_outer_position: [0.0, 0.0] + ensure_labels_bounded: False + ensure_ticks_bounded: False + event_state: 'normal' + fill_padding: False + fixed_preferred_size: None + height: 50 + hpadding: 0 + id: '' + inset_border: True + invisible_layout: False + layout_needed: False + mapper: + orientation: 'bottom' + outer_bounds: (700, 50) + outer_height: 50 + outer_position: (50, 0) + outer_width: 700 + outer_x: 50 + outer_x2: 749 + outer_y: 0 + outer_y2: 49 + overlay_border: True + overlays: [] + padding: [0, 0, 0, 0] + padding_accepts_focus: True + padding_bottom: 0 + padding_left: 0 + padding_right: 0 + padding_top: 0 + pointer: 'arrow' + position: [50, 0] + resizable: 'hv' + small_haxis_style: False + tick_color: 'black' + tick_color_: (0.0, 0.0, 0.0, 1.0) + tick_generator: + tick_in: 5 + tick_interval: 'auto' + tick_label_alignment: 'edge' + tick_label_color: 'black' + tick_label_font: Font(size=16,family=3,we...ace_name='',encoding=0 ) + tick_label_formatter: + tick_label_margin: 2 + tick_label_offset: 8.0 + tick_label_position: 'outside' + tick_label_rotate_angle: 0 + tick_out: 5 + tick_visible: True + tick_weight: 1.0 + ticklabel_cache: [] + title: 'My X-Axis Title' + title_angle: 0.0 + title_color: 'red' + title_color_: (1.0, 0.0, 0.0, 1.0) + title_font: Font(size=20,family=3,we...ace_name='',encoding=0 ) + title_spacing: 'auto' + tools: [] + tooltip: None + underlays: [] + unified_draw: False + use_backbuffer: False + use_draw_order: True + use_selection: False + viewports: [] + visible: True + vpadding: 0 + width: 700 + window: None + x: 50 + x2: 749 + y: 0 + y2: 49 diff --git a/docs/FAQ/source/myTP.grid/ex_chaco_myTP.grid_01.py b/docs/FAQ/source/myTP.grid/ex_chaco_myTP.grid_01.py new file mode 100644 index 000000000..93e4017f2 --- /dev/null +++ b/docs/FAQ/source/myTP.grid/ex_chaco_myTP.grid_01.py @@ -0,0 +1,95 @@ +## ex_chaco_myTP.grid_01.py + +# standard imports +import inspect, os +import numpy as np + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # The dataspace interval between minor grid lines. options are Trait('auto', + # 'auto', Float). If negative, it's a suggestion of how many minor lines to + # use but still uses an algorithm to make a "nice" number of grid lines minor + # grid lines. + myTP.x_grid.grid_interval = 'auto' + + # grid line color. See colorspec. can be e.g. "black" or (0.827, 0.827, + # 0.827, 1.0). line_color_ is useful as a read_only tuple containing the + # numerical color + myTP.x_grid.line_color = 'blue' + myTP.x_grid.line_color_ + + # The style (i.e., the dash pattern) of the grid lines. See the linestyle spec. + # default = LineStyle('solid'). Options are 'dash','dot','solid','dot + # dash','long dash' + # The line_style_ attribute is an array that describes the line style + # in terms of [pixels on, pixels off, ...]. For example, 'dot' corresponds + # to array([ 2., 2.])). Attribute line_style_ overrides the line_style + # attribute. Should have an even number of elements. Odd lengths will work but + # result is non-intuitive. + myTP.x_grid.line_style = 'dot' + myTP.x_grid.line_style_ + + # the thickness of the grid lines, in pixels. Attribute line_weight is + # aliased here. + myTP.x_grid.line_width + + # the grid_mapper method that drives this PlotGrid. Defaults to a + # + myTP.x_grid.mapper + + # the tick_generator method (implimenting AbstractTickGenerator) that drives + # this plot. Defaults to a , + myTP.x_grid.tick_generator + + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + print( tp.myTP.x_grid ) + + myMethods = inspect.getmembers(tp.myTP.x_grid) + myPublics = [thisItem for thisItem in myMethods if thisItem[0][0] != '_'] + print( myPublics ) + + tp.myTP.x_grid.print_traits() diff --git a/docs/FAQ/source/myTP.grid/ex_chaco_myTP.grid_02.py b/docs/FAQ/source/myTP.grid/ex_chaco_myTP.grid_02.py new file mode 100644 index 000000000..5292d4949 --- /dev/null +++ b/docs/FAQ/source/myTP.grid/ex_chaco_myTP.grid_02.py @@ -0,0 +1,105 @@ +## ex_chaco_myTP.grid_02.py + +""" +Simple plot, with grid options +""" + +## -- Notes ----------------------------------------------------------------- + +## -- Imports --------------------------------------------------------------- +# standard imports +import inspect +import numpy as np + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +## -- Let's Begin ----------------------------------------------------------- + +## -- Classes --------------------------------------------------------------- + +class MyPlot( HasTraits ): + '''simple line plot''' + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + + # The dataspace interval between minor grid lines. options are Trait('auto', + # 'auto', Float). If negative, it's a suggestion of how many minor lines to + # use but still uses an algorithm to make a "nice" number of grid lines minor + # grid lines. + myTP.x_grid.grid_interval = 'auto' + + # grid line color. See colorspec. can be e.g. "black" or e.g. (0.827, 0.827, + # 0.827, 1.0). line_color_ is useful as a read_only tuple containing the + # numerical color + myTP.x_grid.line_color = 'blue' + myTP.x_grid.line_color_ + + # The style (i.e., the dash pattern) of the grid lines. See the linestyle spec. + # default = LineStyle('solid'). Options are 'dash','dot','solid','dot + # dash','long dash' + # The line_style_ attribute is an array that describes the line style + # in terms of [pixels on, pixels off, ...]. For example, 'dot' corresponds + # to array([ 2., 2.])). Attribute line_style_ overrides the line_style + # attribute. Should have an even number of elements. Odd lengths will work but + # result is non-intuitive. + myTP.x_grid.line_style = 'dot' + myTP.x_grid.line_style_ + + # the thinknexx of the grid lines, in pixels. Attribute line_weight is + # aliased here. + myTP.x_grid.line_width + + # the grid_mapper method that drives this PlotGrid. Defaults to + # + myTP.x_grid.mapper + + # the tick_generator method (implimenting AbstractTickGenerator) that drives + # this plot. Defaults to ), + myTP.x_grid.tick_generator + + + mySize = (800,600) + myTitle = 'myPlot' + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = mySize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = myTitle, + width = mySize[0], height = mySize[1], + ) + +## -- Functions ------------------------------------------------------------- + +## -- Main ------------------------------------------------------------------ + +if __name__ == "__main__": + + myPlot = MyPlot() + myPlot.configure_traits() + +## -- EOF ------------------------------------------------------------------- diff --git a/docs/FAQ/source/myTP.grid/myTP.grid.rst b/docs/FAQ/source/myTP.grid/myTP.grid.rst new file mode 100644 index 000000000..29d9103d3 --- /dev/null +++ b/docs/FAQ/source/myTP.grid/myTP.grid.rst @@ -0,0 +1,315 @@ +Chaco Plot - Grid Options +========================= + +.. highlight:: python + :linenothreshold: 5 + +.. index:: + pair: Axes; Grid + single: Grid + +Generate a Chaco plot, and output attributes associated with the +grid:: + + ## ex_chaco_myTP.grid_01.py + + # standard imports + import inspect, os + import numpy as np + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import Plot, ArrayPlotData + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # The dataspace interval between minor grid lines. options are Trait('auto', + # 'auto', Float). If negative, it's a suggestion of how many minor lines to + # use but still uses an algorithm to make a "nice" number of grid lines minor + # grid lines. + myTP.x_grid.grid_interval = 'auto' + + # grid line color. See colorspec. can be e.g. "black" or (0.827, 0.827, + # 0.827, 1.0). line_color_ is useful as a read_only tuple containing the + # numerical color + myTP.x_grid.line_color = 'blue' + myTP.x_grid.line_color_ + + # The style (i.e., the dash pattern) of the grid lines. See the linestyle spec. + # default = LineStyle('solid'). Options are 'dash','dot','solid','dot + # dash','long dash' + # The line_style_ attribute is an array that describes the line style + # in terms of [pixels on, pixels off, ...]. For example, 'dot' corresponds + # to array([ 2., 2.])). Attribute line_style_ overrides the line_style + # attribute. Should have an even number of elements. Odd lengths will work but + # result is non-intuitive. + myTP.x_grid.line_style = 'dot' + myTP.x_grid.line_style_ + + # the thickness of the grid lines, in pixels. Attribute line_weight is + # aliased here. + myTP.x_grid.line_width + + # the grid_mapper method that drives this PlotGrid. Defaults to a + # + myTP.x_grid.mapper + + # the tick_generator method (implimenting AbstractTickGenerator) that drives + # this plot. Defaults to a , + myTP.x_grid.tick_generator + + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + print( tp.myTP.x_grid ) + + myMethods = inspect.getmembers(tp.myTP.x_grid) + myPublics = [thisItem for thisItem in myMethods if thisItem[0][0] != '_'] + print( myPublics ) + + tp.myTP.x_grid.print_traits() + +The outputs of the ``print( myPlot.myTP.x_grid )``, ``print( myPublics )`` and the +``tp.myTP.x_grid.print_traits()`` provide useful insight into the grid +characteristics of the plot. + +Excruciating Detail +------------------- + +.. index: + pair: PlotGrid; print_traits() + +Here's the output of the ``print( myPlot.myTP.x_grid )`` call:: + + + +Here's the output from the ``print( myPublics )`` call:: + + [ + ('add_class_trait', >), + ('add_trait', >), + ('add_trait_category', >), + ('add_trait_listener', >), + ('all_trait_names', >), + ('as_coordinates', >), + ('aspect_ratio', None), + ('base_trait', >), + ('bgcolor', 'none'), + ('bgcolor_', (0.0, 0.0, 0.0, 0.0)), + ('bounds', [700, 500]), + ('class_default_traits_view', >), + ('class_editable_traits', >), + ('class_trait_names', >), + ('class_trait_view', >), + ('class_trait_view_elements', >), + ('class_traits', >), + ('cleanup', >), + ('clone_traits', >), + ('component', ), + ('configure_traits', >), + ('container', None), + ('copy_traits', >), + ('copyable_trait_names', >), + ('data_max', None), + ('data_min', None), + ('default_traits_view', >), + ('dispatch', >), + ('do_layout', >), + ('draw', >), + ('draw_select_box', >), + ('edit_traits', >), + ('editable_traits', >), + ('flip_axis', False), + ('get', >), + ('get_absolute_coords', >), + ('get_event_transform', >), + ('get_preferred_size', >), + ('grid_interval', 'auto'), + ('has_traits_interface', >), + ('invalidate', >), + ('invalidate_and_redraw', >), + ('invalidate_draw', >), + ('is_in', >), + ('line_color', 'blue'), + ('line_color_', (0.0, 0.0, 1.0, 1.0)), + ('line_style', 'dot'), + ('line_style_', array([ 2., 2.])), + ('line_width', 1), + ('mapper', ), + ('mapper_updated', >), + ('on_trait_change', >), + ('on_trait_event', >), + ('orientation', 'vertical'), + ('overlay', >), + ('position', [50, 50]), + ('print_traits', >), + ('remove_trait', >), + ('remove_trait_listener', >), + ('request_redraw', >), + ('reset_traits', >), + ('set', >), + ('set_outer_bounds', >), + ('set_outer_position', >), + ('set_trait_dispatch_handler', >), + ('sync_trait', >), + ('tick_generator', ), + ('trait', >), + ('trait_context', >), + ('trait_get', >), + ('trait_items_event', ), + ('trait_monitor', >), + ('trait_names', >), + ('trait_property_changed', ), + ('trait_set', >), + ('trait_setq', >), + ('trait_subclasses', >), + ('trait_view', >), + ('trait_view_elements', >), + ('trait_views', >), + ('traits', >), + ('traits_init', ), + ('traits_inited', ), + ('transverse_bounds', None), + ('use_draw_order', True), + ('validate_trait', >), + ('visible', True), + ('visual_attr_changed', >), + ('wrappers', + { 'new': , + 'ui': , + 'extended': , + 'fast_ui': , + 'same': }) + ] + +Here's the output from the ``tp.myTP.x_grid.print_traits()`` call:: + + _active_tool: None + _backbuffer: None + _cache_valid: False + _layout_needed: True + _tick_extents: array([[ 50., 550.],\n ...,\n [ 50., 550.]]) + _tick_list: None + _tick_positions: array([[ 121., 50.],\n ...,\n [ 678., 50.]]) + _window: None + accepts_focus: True + active_tool: None + aspect_ratio: None + auto_center: True + auto_handle_event: False + backbuffer_padding: True + bgcolor: 'none' + bgcolor_: (0.0, 0.0, 0.0, 0.0) + border_color: 'black' + border_dash: 'solid' + border_visible: False + border_width: 1 + bounds: [700, 500] + classes: [] + component: + container: None + controller: None + cursor_color: 'black' + cursor_style: 'default' + data_max: None + data_min: None + draw_layer: 'overlay' + draw_order: ['background', 'image', 'un..., 'annotation', 'overlay'] + draw_valid: False + drawn_outer_bounds: [0.0, 0.0] + drawn_outer_position: [0.0, 0.0] + event_state: 'normal' + fill_padding: False + fixed_preferred_size: None + flip_axis: False + grid_interval: 'auto' + height: 500 + hpadding: 0 + id: '' + inset_border: True + invisible_layout: False + layout_needed: True + line_color: 'blue' + line_color_: (0.0, 0.0, 1.0, 1.0) + line_style: 'dot' + line_style_: array([ 2., 2.]) + line_weight: 1 + line_width: 1 + mapper: + orientation: 'vertical' + outer_bounds: (700, 500) + outer_height: 500 + outer_position: (50, 50) + outer_width: 700 + outer_x: 50 + outer_x2: 749 + outer_y: 50 + outer_y2: 549 + overlay_border: True + overlays: [] + padding: [0, 0, 0, 0] + padding_accepts_focus: True + padding_bottom: 0 + padding_left: 0 + padding_right: 0 + padding_top: 0 + pointer: 'arrow' + position: [50, 50] + resizable: 'hv' + tick_generator: + tools: [] + tooltip: None + transverse_bounds: None + transverse_mapper: None + underlays: [] + unified_draw: False + use_backbuffer: False + use_draw_order: True + use_selection: False + viewports: [] + visible: True + vpadding: 0 + width: 700 + window: None + x: 50 + x2: 749 + y: 50 + y2: 549 diff --git a/docs/FAQ/source/myTP.plotlabel/ex_chaco_plotlabel_01.png b/docs/FAQ/source/myTP.plotlabel/ex_chaco_plotlabel_01.png new file mode 100644 index 000000000..0aa8bd93d Binary files /dev/null and b/docs/FAQ/source/myTP.plotlabel/ex_chaco_plotlabel_01.png differ diff --git a/docs/FAQ/source/myTP.plotlabel/ex_chaco_plotlabel_01.py b/docs/FAQ/source/myTP.plotlabel/ex_chaco_plotlabel_01.py new file mode 100644 index 000000000..c262314fb --- /dev/null +++ b/docs/FAQ/source/myTP.plotlabel/ex_chaco_plotlabel_01.py @@ -0,0 +1,169 @@ +## ex_chaco_plotlabel_01.py + +# standard imports +import os, inspect + +# numpy imports +from numpy import sin, cos, sqrt, abs, linspace, meshgrid + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import ArrayPlotData, Plot, ColorBar, PlotLabel +from chaco.api import LinearMapper, HPlotContainer, DataLabel + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + # the valentine's plot + # 5 + (-sqrt(1-x^2-(y-abs(x))^2))*cos(30*((1-x^2-(y-abs(x))^2))), + # x is from -1 to 1, y is from -1 to 1.5, z is from 1 to 6 + xA = linspace(-1.0, 1.0, 600) + yA = linspace(-1.0, 1.5, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = (-sqrt( abs( 1 - xMG**2 - (yMG - abs(xMG))**2 ))) + zMG = zMG * cos( 30.0 * ( (1.0 - xMG**2 - (yMG - abs(xMG))**2))) + zMG = zMG + 5.0 + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot. + myTP = Plot( myAPD ) + + # add the image plot to this plot object. If we don't specify the colormapper, + # it defaults to default_colormaps.Spectral + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + ) + + # add the title and padding around the plot + myTP.title = "Valentine's Day Function" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X" + myTP.y_axis.title = "Y" + + # PlotLabel stuff + myTPL = PlotLabel( text = "Howdy" ) + + # Can set the text this way as well. Also, can use newlines + myTPL.text = "True\nLove\nAlways" + + # The color of the label text. + myTPL.color = 'blue' + + # The font for the label text. + myTPL.font = 'swiss 18 bold' + + # The angle of rotation of the label. + myTPL.angle = 0 # try 45 + + # misc + myTPL.bgcolor = 'cornflowerblue' # see ``cclor_table`` in enable/colors.py + myTPL.border_width = 3 # defaults to 0 pixels + myTPL.border_color = 'blue' # defaults to black + myTPL.border_visible = True # defaults to True + myTPL.margin = 5 # number of pixels of margin between the + # text and the plotlabel border, in both + # X and Y dims + myTPL.line_spacing = 20 # number of pixels of spacing between lines of text + + # layout related + # Horizontal/vertical justification used if the label has more space + # than it needs. + myTPL.hjustify = 'center' # Enum("center", "left", "right") + myTPL.vjustify = 'center' # Enum("center", "bottom", "top") + + # The position of this label relative to the object it is overlaying. + # Can be "top", "left", "right", "bottom", and optionally can be preceeded + # by the words "inside" or "outside", separated by a space. If "inside" + # and "outside" are not provided, then defaults to "outside". + # Examples: 'inside top', 'outside right' + myTPL.overlay_position = 'inside right' # Trait("outside top", Str, None) + + myTPL.padding_left = 10 # extra padding added to the PlotLabel layout, in pixels + myTPL.padding_right + myTPL.padding_top + myTPL.padding_bottom + + # By default, this acts like a component and will render on the main plot + # layer unless its component attribute gets set. + #myTPL.draw_layer + + # The label has a fixed height and can be resized horizontally. (Overrides + # PlotComponent.) + myTPL.resizable = 'h' # defaults to 'h' + + # methods + #myTPL.do_layout() # Tells this component to do layout. + myTPL.get_preferred_size() # Returns the label?s preferred size, in pixels. + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + + # inform the Traits plot that it has a Traits PlotLabel overlay, and inform + # the Traits PlotLabel instance that it is being overlayed onto the Traits + # Plot + myTP.overlays.append( myTPL ) + myTPL.component = myTP + + # Note that we could also have overlayed the PlotLabel on the Traits + # Horizontal Plot container, myHPC. Then the positions would refer to + # the plot container and not just to the plot + #myHPC.overlays.append( myTPL ) + #myTPL.component = myHPC + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myHPC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + # traits of the Traits Plot + tp.myTP.print_traits() + + # traits of the Traits Horizontal Plot Container + tp.myHPC.print_traits() + + # traits of the Traits Plot Label + tp.myTPL.print_traits() diff --git a/docs/FAQ/source/myTP.plotlabel/myTP.plotlabel.rst b/docs/FAQ/source/myTP.plotlabel/myTP.plotlabel.rst new file mode 100644 index 000000000..01108b048 --- /dev/null +++ b/docs/FAQ/source/myTP.plotlabel/myTP.plotlabel.rst @@ -0,0 +1,527 @@ +Chaco Plot - Plot Label Options +=============================== + +.. highlight:: python + :linenothreshold: 5 + +.. index:: + pair: Title; Plot Label + single: Plot Label + single: Function; Valentine's Day + +Let's generate a plot with a plot label. The code is:: + + ## ex_chaco_plotlabel_01.py + + # standard imports + import os, inspect + + # numpy imports + from numpy import sin, cos, sqrt, abs, linspace, meshgrid + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import ArrayPlotData, Plot, ColorBar, PlotLabel + from chaco.api import LinearMapper, HPlotContainer, DataLabel + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + # create an interesting scalar field for the image plot + # the valentine's plot + # 5 + (-sqrt(1-x^2-(y-abs(x))^2))*cos(30*((1-x^2-(y-abs(x))^2))), + # x is from -1 to 1, y is from -1 to 1.5, z is from 1 to 6 + xA = linspace(-1.0, 1.0, 600) + yA = linspace(-1.0, 1.5, 600) + ( xMG,yMG ) = meshgrid( xA,yA ) + zMG = (-sqrt( abs( 1 - xMG**2 - (yMG - abs(xMG))**2 ))) + zMG = zMG * cos( 30.0 * ( (1.0 - xMG**2 - (yMG - abs(xMG))**2))) + zMG = zMG + 5.0 + + # Create an ArrayPlotData object and give it this data + myAPD = ArrayPlotData() + myAPD.set_data( "Z", zMG ) + myAPD.set_data( "X",xA ) + myAPD.set_data( "Y",yA ) + + # Create the plot. + myTP = Plot( myAPD ) + + # add the image plot to this plot object. If we don't specify the colormapper, + # it defaults to default_colormaps.Spectral + myTP.img_plot( + "Z", + xbounds = (xA[0],xA[-1]), + ybounds = (yA[0],yA[-1]), + ) + + # add the title and padding around the plot + myTP.title = "Valentine's Day Function" + myTP.padding = 50 + + # grids, fonts, etc + myTP.x_axis.title = "X" + myTP.y_axis.title = "Y" + + # PlotLabel stuff + myTPL = PlotLabel( text = "Howdy" ) + + # Can set the text this way as well. Also, can use newlines + myTPL.text = "True\nLove\nAlways" + + # The color of the label text. + myTPL.color = 'blue' + + # The font for the label text. + myTPL.font = 'swiss 18 bold' + + # The angle of rotation of the label. + myTPL.angle = 0 # try 45 + + # misc + myTPL.bgcolor = 'cornflowerblue' # see ``cclor_table`` in enable/colors.py + myTPL.border_width = 3 # defaults to 0 pixels + myTPL.border_color = 'blue' # defaults to black + myTPL.border_visible = True # defaults to True + myTPL.margin = 5 # number of pixels of margin between the + # text and the plotlabel border, in both + # X and Y dims + myTPL.line_spacing = 20 # number of pixels of spacing between lines of text + + # layout related + # Horizontal/vertical justification used if the label has more space + # than it needs. + myTPL.hjustify = 'center' # Enum("center", "left", "right") + myTPL.vjustify = 'center' # Enum("center", "bottom", "top") + + # The position of this label relative to the object it is overlaying. + # Can be "top", "left", "right", "bottom", and optionally can be preceeded + # by the words "inside" or "outside", separated by a space. If "inside" + # and "outside" are not provided, then defaults to "outside". + # Examples: 'inside top', 'outside right' + myTPL.overlay_position = 'inside right' # Trait("outside top", Str, None) + + myTPL.padding_left = 10 # extra padding added to the PlotLabel layout, in pixels + myTPL.padding_right + myTPL.padding_top + myTPL.padding_bottom + + # By default, this acts like a component and will render on the main plot + # layer unless its component attribute gets set. + #myTPL.draw_layer + + # The label has a fixed height and can be resized horizontally. (Overrides + # PlotComponent.) + myTPL.resizable = 'h' # defaults to 'h' + + # methods + #myTPL.do_layout() # Tells this component to do layout. + myTPL.get_preferred_size() # Returns the label?s preferred size, in pixels. + + # generate a ColorBar. pulls its colormapper from the myTP Plot object + myTCB = ColorBar( + plot = myTP, + index_mapper = LinearMapper( range = myTP.color_mapper.range ), + orientation = 'v', + resizable = 'v', + width = 40, + padding = 30, + ) + + # set the padding of the ColorBar to match the padding of the plot + myTCB.padding_top = myTP.padding_top + myTCB.padding_bottom = myTP.padding_bottom + + # build up a single container for the colorbar and the image + myHPC = HPlotContainer( use_backbuffer = True ) + myHPC.add( myTP ) + myHPC.add( myTCB ) + + # inform the Traits plot that it has a Traits PlotLabel overlay, and inform + # the Traits PlotLabel instance that it is being overlayed onto the Traits + # Plot + myTP.overlays.append( myTPL ) + myTPL.component = myTP + + # Note that we could also have overlayed the PlotLabel on the Traits + # Horizontal Plot container, myHPC. Then the positions would refer to + # the plot container and not just to the plot + #myHPC.overlays.append( myTPL ) + #myTPL.component = myHPC + + # set up the view for both the graphics and control + traits_view = View( + Item( + 'myHPC', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + # traits of the Traits Plot + tp.myTP.print_traits() + + # traits of the Traits Horizontal Plot Container + tp.myHPC.print_traits() + + # traits of the Traits Plot Label + tp.myTPL.print_traits() + +The resulting graphic is + +.. figure:: ex_chaco_plotlabel_01.png + :scale: 100 % + :align: center + :alt: Chaco PlotLabel Demo + + Chaco PlotLabel Demo + +Found Code +---------- + +from plot.py, +:: + + # The PlotLabel object that contains the title. + _title = Instance(PlotLabel) + + if not self._title: + self._title = PlotLabel(font="swiss 16", visible=False, + overlay_position="top", component=self) + + def _set_title_position(self, pos): + if self._title is not None: + self._title.overlay_position = pos + +Excrutiating Detail +------------------- + +The output of the ``tp.myTP.print_traits()`` line is:: + + _active_tool: None + _auto_color_idx: -1 + _auto_edge_color_idx: -1 + _auto_face_color_idx: -1 + _backbuffer: None + _cached_preferred_size: (100, 100) + _children_draw_mode: 'default' + _components: [] + _layout_needed: False + _lookup_cache: None + _plot_ui_info: None + _prev_event_handlers: set([]) + _title: + _window: None + accepts_focus: True + active_tool: None + aspect_ratio: None + auto_center: True + auto_colors: ['green', 'lightgreen', 'b...nk', 'darkgray', 'silver'] + auto_handle_event: False + auto_size: False + backbuffer_padding: True + bgcolor: 'white' + bgcolor_: (1.0, 1.0, 1.0, 1.0) + border_color: 'black' + border_color_: (0.0, 0.0, 0.0, 1.0) + border_dash: 'solid' + border_dash_: None + border_visible: True + border_width: 1 + bounds: [600, 500] + classes: [] + color_mapper: + components: [] + container: + container_under_layers: ('background', 'image', 'underlay', 'plot') + controller: None + cursor_color: 'black' + cursor_style: 'default' + data: + datasources: {'Z': } + default_index: None + default_origin: 'bottom left' + default_size: (0, 0) + draw_layer: 'plot' + draw_order: ['background', 'image', 'u..., 'annotation', 'overlay'] + draw_valid: False + drawn_outer_bounds: [0.0, 0.0] + drawn_outer_position: [0.0, 0.0] + event_state: 'normal' + fill_padding: False + fit_components: '' + fit_window: True + fixed_preferred_size: None + height: 500 + hpadding: 100 + id: '' + index_axis: + index_grid: + index_mapper: + index_range: + index_scale: 'linear' + inset_border: True + intercept_events: True + invisible_layout: False + layout_controller: None + layout_needed: False + legend: + legend_alignment: 'ur' + orientation: 'h' + origin: 'bottom left' + outer_bounds: (700, 600) + outer_height: 600 + outer_position: (0, 0) + outer_width: 700 + outer_x: 0 + outer_x2: 699 + outer_y: 0 + outer_y2: 599 + overlay_border: True + overlays: [] + padding: [50, 50, 50, 50] + padding_accepts_focus: True + padding_bottom: 50 + padding_left: 50 + padding_right: 50 + padding_top: 50 + plot_components: [] + plots: {'plot0': []} + pointer: 'arrow' + position: [50, 50] + range2d: + renderer_map: {'bar': } + resizable: 'hv' + resolver: None + title: "Valentine's Day Function" + title_angle: 0 + title_color: 'black' + title_font: Font(size=16,family=1,weig... face_name='',encoding=0 ) + title_position: 'top' + title_text: "Valentine's Day Function" + tools: [] + tooltip: None + underlays: [] + unified_draw: False + use_backbuffer: False + use_draw_order: True + use_selection: False + value_axis: + value_grid: + value_mapper: + value_range: + value_scale: 'linear' + viewports: [] + visible: True + vpadding: 100 + width: 600 + window: None + x: 50 + x2: 649 + x_axis: + x_grid: + x_mapper: + y: 50 + y2: 549 + y_axis: + y_grid: + y_mapper: + +..index: + pair: HPlotContainer; print_traits() + +The output of the ``tp.myHPC.print_traits()`` line is:: + + _active_tool: None + _backbuffer: > > + _cached_preferred_size: () + _children_draw_mode: 'default' + _components: [] + _layout_needed: False + _lookup_cache: None + _prev_event_handlers: set([]) + _window: None + accepts_focus: True + active_tool: None + aspect_ratio: None + auto_center: True + auto_handle_event: False + auto_size: False + backbuffer_padding: True + bgcolor: 'white' + bgcolor_: (1.0, 1.0, 1.0, 1.0) + border_color: 'black' + border_dash: 'solid' + border_visible: False + border_width: 1 + bounds: [800, 600] + classes: [] + components: [] + container: None + container_under_layers: ('background', 'image', 'underlay', 'plot') + controller: None + cursor_color: 'black' + cursor_style: 'default' + default_size: (0, 0) + draw_layer: 'plot' + draw_order: ['background', 'image', 'u..., 'annotation', 'overlay'] + draw_valid: True + drawn_outer_bounds: [800, 600] + drawn_outer_position: [0, 0] + event_state: 'normal' + fill_padding: False + fit_components: '' + fit_window: True + fixed_preferred_size: None + height: 600 + hpadding: 0 + id: '' + inset_border: True + intercept_events: True + invisible_layout: False + layout_controller: None + layout_needed: False + other_dimension: 'v' + outer_bounds: (800, 600) + outer_height: 600 + outer_position: (0, 0) + outer_width: 800 + outer_x: 0 + outer_x2: 799 + outer_y: 0 + outer_y2: 599 + overlay_border: True + overlays: [] + padding: [0, 0, 0, 0] + padding_accepts_focus: True + padding_bottom: 0 + padding_left: 0 + padding_right: 0 + padding_top: 0 + parent: None + plot_components: [] + pointer: 'arrow' + position: [0, 0] + resizable: 'hv' + resolver: None + spacing: 0.0 + stack_dimension: 'h' + stack_order: 'left_to_right' + tools: [] + tooltip: None + underlays: [] + unified_draw: False + use_backbuffer: True + use_draw_order: True + use_selection: False + valign: 'bottom' + viewports: [] + visible: True + vpadding: 0 + width: 800 + window: None + x: 0 + x2: 799 + y: 0 + y2: 599 + +.. index:: + pair: PlotLabel; print_traits() + +The output of the ``tp.myTPL.print_traits()`` line is:: + + _active_tool: None + _backbuffer: None + _label: + _layout_needed: True + _window: None + accepts_focus: True + active_tool: None + angle: 0.0 + aspect_ratio: None + auto_center: True + auto_handle_event: False + backbuffer_padding: True + bgcolor: 'cornflowerblue' + border_color: 'blue' + border_dash: 'solid' + border_visible: True + border_width: 3 + bounds: [80.0, 500] + classes: [] + color: 'blue' + component: + container: None + controller: None + cursor_color: 'black' + cursor_style: 'default' + draw_layer: 'overlay' + draw_order: ['background', 'image', 'un..., 'annotation', 'overlay'] + draw_valid: False + drawn_outer_bounds: [0.0, 0.0] + drawn_outer_position: [0.0, 0.0] + event_state: 'normal' + fill_padding: False + fixed_preferred_size: None + font: Font(size=18,family=1,weigh... face_name='',encoding=0 ) + height: 500 + hjustify: 'center' + hpadding: 10 + id: '' + inset_border: True + invisible_layout: False + layout_needed: True + line_spacing: 20 + margin: 5 + outer_bounds: (90.0, 500) + outer_height: 500 + outer_position: (549.0, 50) + outer_width: 90.0 + outer_x: 549.0 + outer_x2: 638.0 + outer_y: 50 + outer_y2: 549 + overlay_border: True + overlay_position: 'inside right' + overlays: [] + padding: [10, 0, 0, 0] + padding_accepts_focus: True + padding_bottom: 0 + padding_left: 10 + padding_right: 0 + padding_top: 0 + pointer: 'arrow' + position: [559.0, 50] + resizable: 'h' + text: 'True\nLove\nAlways' + tools: [] + tooltip: None + underlays: [] + unified_draw: False + use_backbuffer: False + use_draw_order: True + use_selection: False + viewports: [] + visible: True + vjustify: 'center' + vpadding: 0 + width: 80.0 + window: None + x: 559.0 + x2: 638.0 + y: 50 + y2: 549 diff --git a/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_01.png b/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_01.png new file mode 100644 index 000000000..32a5496ab Binary files /dev/null and b/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_01.png differ diff --git a/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_01.py b/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_01.py new file mode 100644 index 000000000..b040258e1 --- /dev/null +++ b/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_01.py @@ -0,0 +1,116 @@ +## ex_chaco_myTP.range_01.py + +# standard imports +import inspect, os +import numpy as np + +# Enthought imports +from enable.api import ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # The actual value of the lower left/upper right bounds of this range as (x,y) + # points. To set them, use low_setting/high_setting. + myTP.range2d.low + myTP.range2d.high + + # a 2-tuple of lower left/upper right (x,y) bounds. Either can be set to + # 'auto', causing the range to autocalculate + myTP.range2d.low_setting + myTP.range2d.high_setting + + # Sets all the bounds of the range simultaneously. Lower left/upper right + # corners of the data range. + # Ex. myTP.range2d.set_bounds( (1,2), (3,4) ) sets the lower left to (1,2) and + # the upper right to (3,4) + myTP.range2d.set_bounds + + # ranges in the x- and y- dimensions. These are DataRange1D objects, one for + # the x- axis and one for the y- axis + myTP.range2d.x_range + myTP.range2d.y_range + + # the low/high values for the x-/y- axes. can be set to + # 'auto': The lower bound is automatically set at or below the minimum + # of the data. + # 'track': The lower bound tracks the upper bound by tracking_amount. + # CFloat: An explicit value for the lower bound + # set with the appropriate _setting method + myTP.range2d.x_range.low + myTP.range2d.x_range.high + myTP.range2d.y_range.low + myTP.range2d.y_range.high + + myTP.range2d.x_range.low_setting + myTP.range2d.x_range.high_setting + myTP.range2d.y_range.low_setting + myTP.range2d.y_range.high_setting + + # Do 'auto' bounds imply an exact fit to the data? (One Boolean per dimension) + # If False, the bounds pad a little bit of margin on either side. Setting + # the range2d.tight_bounds does not work (i.e. myTP.range2d.tight_bounds = + # (False,False)) does nothing. Defaults to (True,True) which causes the axes + # bounds to exactly correspond to the data + myTP.range2d.x_range.tight_bounds = False + myTP.range2d.y_range.tight_bounds = False + + # The minimum percentage difference between low and high for each dimension. + # That is, (high-low) >= epsilon * low. + myTP.range2d.epsilon + + # If any of the bounds is 'auto', this method refreshes the actual low and + # high values from the set of the view filters' data sources. + myTP.range2d.refresh() + + # Resets the bounds of this range. + myTP.range2d.reset() + + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + print( tp.myTP.range2d ) + + myMethods = inspect.getmembers(tp.myTP.range2d) + myPublics = [thisItem for thisItem in myMethods if thisItem[0][0] != '_'] + print( myPublics ) + + tp.myTP.range2d.print_traits() diff --git a/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_02.py b/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_02.py new file mode 100644 index 000000000..5577a3f51 --- /dev/null +++ b/docs/FAQ/source/myTP.range/ex_chaco_myTP.range_02.py @@ -0,0 +1,123 @@ +## ex_chaco_myTP.range_02.py + +""" +Simple plot, with plot range options +""" + +## -- Notes ----------------------------------------------------------------- + +## -- Imports --------------------------------------------------------------- +# standard imports +import inspect +import numpy as np + +# Enthought imports +from enable.api import ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +## -- Let's Begin ----------------------------------------------------------- + +## -- Classes --------------------------------------------------------------- + +class MyPlot( HasTraits ): + '''simple line plot''' + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # The actual value of the lower left/upper right bounds of this range as (x,y) + # points. To set them, use low_setting/high_setting. + myTP.range2d.low + myTP.range2d.high + + # a 2-tuple of lower left/upper right (x,y) bounds. Either can be set to + # 'auto', causing the range to autocalculate + myTP.range2d.low_setting + myTP.range2d.high_setting + + # Sets all the bounds of the range simultaneously. Lower left/upper right + # corners of the data range. + # Ex. myTP.range2d.set_bounds( (1,2), (3,4) ) sets the lower left to (1,2) and + # the upper right to (3,4) + myTP.range2d.set_bounds + + # ranges in the x- and y- dimensions. These are DataRange1D objects, one for + # the x- axis and one for the y- axis + myTP.range2d.x_range + myTP.range2d.y_range + + # the low/high values for the x-/y- axes. can be set to + # 'auto': The lower bound is automatically set at or below the minimum + # of the data. + # 'track': The lower bound tracks the upper bound by tracking_amount. + # CFloat: An explicit value for the lower bound + # set with the appropriate _setting method + myTP.range2d.x_range.low + myTP.range2d.x_range.high + myTP.range2d.y_range.low + myTP.range2d.y_range.high + + myTP.range2d.x_range.low_setting + myTP.range2d.x_range.high_setting + myTP.range2d.y_range.low_setting + myTP.range2d.y_range.high_setting + + # Do 'auto' bounds imply an exact fit to the data? (One Boolean per dimension) + # If False, the bounds pad a little bit of margin on either side. Setting + # the range2d.tight_bounds does not work (i.e. myTP.range2d.tight_bounds = + # (False,False)) does nothing. Defaults to (True,True) which causes the axes + # bounds to exactly correspond to the data + myTP.range2d.x_range.tight_bounds + myTP.range2d.y_range.tight_bounds + + # The minimum percentage difference between low and high for each dimension. + # That is, (high-low) >= epsilon * low. + myTP.range2d.epsilon + + # If any of the bounds is 'auto', this method refreshes the actual low and + # high values from the set of the view filters' data sources. + myTP.range2d.refresh() + + # Resets the bounds of this range. + myTP.range2d.reset() + + mySize = (800,600) + myTitle = 'myPlot' + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = mySize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = myTitle, + width = mySize[0], height = mySize[1], + ) + +## -- Functions ------------------------------------------------------------- + +## -- Main ------------------------------------------------------------------ + +if __name__ == "__main__": + + myPlot = MyPlot() + myPlot.configure_traits() + +## -- EOF ------------------------------------------------------------------- diff --git a/docs/FAQ/source/myTP.range/myTP.range.rst b/docs/FAQ/source/myTP.range/myTP.range.rst new file mode 100644 index 000000000..5bf72e468 --- /dev/null +++ b/docs/FAQ/source/myTP.range/myTP.range.rst @@ -0,0 +1,227 @@ +Chaco Plot - Axes Range Options +=============================== + +.. highlight:: python + :linenothreshold: 5 + +.. index:: + pair: Axes; Range + +The range of a 2D Chaco plot is controled by the ``range2d`` object. Let's generate +a Chaco plot, and output attributes associated with the range of the axes:: + + ## ex_chaco_myTP.range_01.py + + # standard imports + import inspect, os + import numpy as np + + # Enthought imports + from enable.api import ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import Plot, ArrayPlotData + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + # The actual value of the lower left/upper right bounds of this range as (x,y) + # points. To set them, use low_setting/high_setting. + myTP.range2d.low + myTP.range2d.high + + # a 2-tuple of lower left/upper right (x,y) bounds. Either can be set to + # 'auto', causing the range to autocalculate + myTP.range2d.low_setting + myTP.range2d.high_setting + + # Sets all the bounds of the range simultaneously. Lower left/upper right + # corners of the data range. + # Ex. myTP.range2d.set_bounds( (1,2), (3,4) ) sets the lower left to (1,2) and + # the upper right to (3,4) + myTP.range2d.set_bounds + + # ranges in the x- and y- dimensions. These are DataRange1D objects, one for + # the x- axis and one for the y- axis + myTP.range2d.x_range + myTP.range2d.y_range + + # the low/high values for the x-/y- axes. can be set to + # 'auto': The lower bound is automatically set at or below the minimum + # of the data. + # 'track': The lower bound tracks the upper bound by tracking_amount. + # CFloat: An explicit value for the lower bound + # set with the appropriate _setting method + myTP.range2d.x_range.low + myTP.range2d.x_range.high + myTP.range2d.y_range.low + myTP.range2d.y_range.high + + myTP.range2d.x_range.low_setting + myTP.range2d.x_range.high_setting + myTP.range2d.y_range.low_setting + myTP.range2d.y_range.high_setting + + # Do 'auto' bounds imply an exact fit to the data? (One Boolean per dimension) + # If False, the bounds pad a little bit of margin on either side. Setting + # the range2d.tight_bounds does not work (i.e. myTP.range2d.tight_bounds = + # (False,False)) does nothing. Defaults to (True,True) which causes the axes + # bounds to exactly correspond to the data + myTP.range2d.x_range.tight_bounds = False + myTP.range2d.y_range.tight_bounds = False + + # The minimum percentage difference between low and high for each dimension. + # That is, (high-low) >= epsilon * low. + myTP.range2d.epsilon + + # If any of the bounds is 'auto', this method refreshes the actual low and + # high values from the set of the view filters' data sources. + myTP.range2d.refresh() + + # Resets the bounds of this range. + myTP.range2d.reset() + + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + print( tp.myTP.range2d ) + + myMethods = inspect.getmembers(tp.myTP.range2d) + myPublics = [thisItem for thisItem in myMethods if thisItem[0][0] != '_'] + print( myPublics ) + + tp.myTP.range2d.print_traits() + +The reader is encouraged to examine the outputs of the ``print( myPlot.myTP.range2d )``, +the ``print( myPublics )`` and the the ``tp.myTP.range2d.print_traits()`` calls. +The outputs are reproduced under Excruciating Detail below. + +Excruciating Detail +------------------- + +.. index + pair: DataRange2D; print_traits() + +The result of the ``print( myPlot.myTP.range2d )`` call is:: + + + +The output from the ``print( myPublics )`` call is:: + + [ + ('add', >), + ('add_class_trait', >), + ('add_trait', >), + ('add_trait_category', >), + ('add_trait_listener', >), + ('all_trait_names', >), + ('base_trait', >), + ('bound_data', >), + ('class_default_traits_view', >), + ('class_editable_traits', >), + ('class_trait_names', >), + ('class_trait_view', >), + ('class_trait_view_elements', >), + ('class_traits', >), + ('clip_data', >), + ('clone_traits', >), + ('configure_traits', >), + ('copy_traits', >), + ('copyable_trait_names', >), + ('default_traits_view', >), + ('edit_traits', >), + ('editable_traits', >), + ('epsilon', (0.0001, 0.0001)), + ('get', >), + ('has_traits_interface', >), + ('mask_data', >), + ('on_trait_change', >), + ('on_trait_event', >), + ('print_traits', >), + ('refresh', >), + ('remove', >), + ('remove_trait', >), + ('remove_trait_listener', >), + ('reset', >), + ('reset_traits', >), + ('set', >), + ('set_bounds', >), + ('set_trait_dispatch_handler', >), + ('sync_trait', >), + ('trait', >), + ('trait_context', >), + ('trait_get', >), + ('trait_items_event', ), + ('trait_monitor', >), + ('trait_names', >), + ('trait_property_changed', ), + ('trait_set', >), + ('trait_setq', >), + ('trait_subclasses', >), + ('trait_view', >), + ('trait_view_elements', >), + ('trait_views', >), + ('traits', >), + ('traits_init', ), + ('traits_inited', ), + ('validate_trait', >), + ('wrappers', + { 'new': , + 'ui': , + 'extended': , + 'fast_ui': , + 'same': }) + ] + +Here's the output from the ``tp.myTP.range2d.print_traits()`` call:: + + _high_setting: ('auto', 'auto') + _high_value: (inf, inf) + _low_setting: ('auto', 'auto') + _low_value: (-inf, -inf) + _xrange: + _yrange: + epsilon: (0.0001, 0.0001) + high: (8.0, 0.4) + high_setting: ('auto', 'auto') + low: (-8.0, -0.4) + low_setting: ('auto', 'auto') + sources: [] + tight_bounds: (True, True) + x_range: + y_range: diff --git a/docs/FAQ/source/myTP.title/ex_chaco_myTP.title_01.png b/docs/FAQ/source/myTP.title/ex_chaco_myTP.title_01.png new file mode 100644 index 000000000..e5dfe3942 Binary files /dev/null and b/docs/FAQ/source/myTP.title/ex_chaco_myTP.title_01.png differ diff --git a/docs/FAQ/source/myTP.title/ex_chaco_myTP.title_01.py b/docs/FAQ/source/myTP.title/ex_chaco_myTP.title_01.py new file mode 100644 index 000000000..9eb8b66a6 --- /dev/null +++ b/docs/FAQ/source/myTP.title/ex_chaco_myTP.title_01.py @@ -0,0 +1,77 @@ +## ex_chaco_myTP.title_01.py + +# standard imports +import os, inspect +import numpy as np + +# Enthought imports +from enable.api import Component, ComponentEditor +from traits.api import HasTraits +from traitsui.api import Item, Group, View +from chaco.api import Plot, ArrayPlotData + +# defines +windowSize = (800,600) + +# window title is file name +windowTitle = os.path.split(__file__)[1] + +class TraitedPlot( HasTraits ): + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + myTP.padding = 50 # pixels twixt plot and window edge. + + # most title attributes delegate to the underlying _title attribute, which + # is a PlotLabel object. + myTP.title = 'My Plot Title' # title appearing on plot + myTP.title_angle = 0 # angle of the title in degrees + myTP.title_color = 'blue' # title color. see colorspec + myTP.title_font = "swiss 16" # title font. see fontspec + myTP.title_position = 'top' # top, bottom, left, right + myTP.title_spacing = 'auto' # spacing between the axis line and the title + + myTP._title.hjustify = 'center' # left, right or cener + myTP._title.vjustify = 'center' # top, bottom or center + + mySize = (800,600) + myTitle = 'myPlot' + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + +if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + print( type(tp.myTP._title) ) + + # print only the public members of the list + membersList = inspect.getmembers( tp.myTP._title ) + publicList = [thisItem for thisItem in membersList if thisItem[0][0] != '_'] + print( publicList ) + + tp.myTP._title.print_traits() diff --git a/docs/FAQ/source/myTP.title/myTP.title.rst b/docs/FAQ/source/myTP.title/myTP.title.rst new file mode 100644 index 000000000..2a2f51dac --- /dev/null +++ b/docs/FAQ/source/myTP.title/myTP.title.rst @@ -0,0 +1,294 @@ +Chaco Plot - Title Options +========================== + +.. highlight:: python + :linenothreshold: 5 + +.. index:: + pair: Title; Plot + +Plot titles are Delegates to a PlotLabel object, which is stored in the Plot +object in the ``_title`` attribute. This code generates a Chaco plot, with +explicit plot title options and introspection into the attributes involving +the plot's title:: + + ## ex_chaco_myTP.title_01.py + + # standard imports + import os, inspect + import numpy as np + + # Enthought imports + from enable.api import Component, ComponentEditor + from traits.api import HasTraits + from traitsui.api import Item, Group, View + from chaco.api import Plot, ArrayPlotData + + # defines + windowSize = (800,600) + + # window title is file name + windowTitle = os.path.split(__file__)[1] + + class TraitedPlot( HasTraits ): + + numPoints = 100 + extent = 2.0 * np.pi + phaseA = np.linspace( -extent,extent,numPoints ) + amplitudeA = np.sin( phaseA ) * np.exp(-abs( phaseA )) + + myTADP = ArrayPlotData() + myTADP.set_data( 'X',phaseA ) + myTADP.set_data( 'Y',amplitudeA ) + + myTP = Plot( myTADP ) + myTP.plot( + ("X", "Y"), + type = 'line', + ) + + myTP.padding = 50 # pixels twixt plot and window edge. + + # most title attributes delegate to the underlying _title attribute, which + # is a PlotLabel object. + myTP.title = 'My Plot Title' # title appearing on plot + myTP.title_angle = 0 # angle of the title in degrees + myTP.title_color = 'blue' # title color. see colorspec + myTP.title_font = "swiss 16" # title font. see fontspec + myTP.title_position = 'top' # top, bottom, left, right + myTP.title_spacing = 'auto' # spacing between the axis line and the title + + myTP._title.hjustify = 'center' # left, right or cener + myTP._title.vjustify = 'center' # top, bottom or center + + mySize = (800,600) + myTitle = 'myPlot' + traits_view = View( + Group( + Item( + 'myTP', + editor = ComponentEditor(size = windowSize), + show_label = False, + ), + orientation = "vertical", + ), + resizable = True, + title = windowTitle, + ) + + if __name__ == "__main__": + + tp = TraitedPlot() + tp.configure_traits() + + print( type(tp.myTP._title) ) + + # print only the public members of the list + membersList = inspect.getmembers( tp.myTP._title ) + publicList = [thisItem for thisItem in membersList if thisItem[0][0] != '_'] + print( publicList ) + + tp.myTP._title.print_traits() + +The reader is encouraged to examine the outputs of the +``print( type(tp.myTP._title) )``, the ``print( publiList )`` and the +``tp.myTP._title.print_traits()`` lines for insight into the behavior of +the title attribute. + +Found Code +---------- + +From plot.py, default title construction:: + + if not self._title: + self._title = PlotLabel( + font = "swiss 16", + visible = False, + overlay_position = "top", + component = self ) + + if title is not None: + self.title = title + +Excruciating Detail +------------------- + +.. index: + pair: PlotLabel; print_traits() + +The output of the ``print( type(tp.myTP._title) )`` line is:: + + + +The output of the ``print( publiList )`` line is:: + + [ + ('add_class_trait', >), + ('add_trait', >), + ('add_trait_category', >), + ('add_trait_listener', >), + ('all_trait_names', >), + ('as_coordinates', >), + ('aspect_ratio', None), + ('base_trait', >), + ('bounds', [700, 50]), + ('class_default_traits_view', >), + ('class_editable_traits', >), + ('class_trait_names', >), + ('class_trait_view', >), + ('class_trait_view_elements', >), + ('class_traits', >), + ('cleanup', >), + ('clone_traits', >), + ('component', ), + ('configure_traits', >), + ('container', None), + ('controller', None), + ('copy_traits', >), + ('copyable_trait_names', >), + ('default_traits_view', >), + ('dispatch', >), + ('do_layout', >), + ('draw', >), + ('draw_layer', 'overlay'), + ('draw_select_box', >), + ('edit_traits', >), + ('editable_traits', >), + ('event_state', 'normal'), + ('get', >), + ('get_absolute_coords', >), + ('get_event_transform', >), + ('get_preferred_size', >), + ('has_traits_interface', >), + ('hjustify', 'center'), + ('invalidate_and_redraw', >), + ('invalidate_draw', >), + ('is_in', >), + ('on_trait_change', >), + ('on_trait_event', >), + ('overlay', >), + ('overlay_position', 'top'), + ('overlays', []), + ('position', [50, 550]), + ('print_traits', >), + ('remove_trait', >), + ('remove_trait_listener', >), + ('request_redraw', >), + ('reset_traits', >), + ('set', >), + ('set_outer_bounds', >), + ('set_outer_position', >), + ('set_trait_dispatch_handler', >), + ('sync_trait', >), + ('tools', []), + ('trait', >), + ('trait_context', >), + ('trait_get', >), + ('trait_items_event', ), + ('trait_monitor', >), + ('trait_names', >), + ('trait_property_changed', ), + ('trait_set', >), + ('trait_setq', >), + ('trait_subclasses', >), + ('trait_view', >), + ('trait_view_elements', >), + ('trait_views', >), + ('traits', >), + ('traits_init', ), + ('traits_inited', ), + ('underlays', []), + ('use_draw_order', True), + ('validate_trait', >), + ('visible', True), + ('vjustify', 'center'), + ('wrappers', + { 'new': , + 'ui': , + 'extended': , + 'fast_ui': , + 'same': })] + +The output of the ``tp.myTP._title.print_traits()`` line is:: + + _active_tool: None + _backbuffer: None + _label: + _layout_needed: True + _window: None + accepts_focus: True + active_tool: None + angle: 0.0 + aspect_ratio: None + auto_center: True + auto_handle_event: False + backbuffer_padding: True + bgcolor: 'transparent' + border_color: 'black' + border_dash: 'solid' + border_visible: True + border_width: 0 + bounds: [700, 50] + classes: [] + color: 'blue' + component: + container: None + controller: None + cursor_color: 'black' + cursor_style: 'default' + draw_layer: 'overlay' + draw_order: ['background', 'image', 'un..., 'annotation', 'overlay'] + draw_valid: False + drawn_outer_bounds: [0.0, 0.0] + drawn_outer_position: [0.0, 0.0] + event_state: 'normal' + fill_padding: False + fixed_preferred_size: None + font: Font(size=16,family=1,weigh... face_name='',encoding=0 ) + height: 50 + hjustify: 'center' + hpadding: 0 + id: '' + inset_border: True + invisible_layout: False + layout_needed: True + line_spacing: 5 + margin: 2 + outer_bounds: (700, 50) + outer_height: 50 + outer_position: (50, 550) + outer_width: 700 + outer_x: 50 + outer_x2: 749 + outer_y: 550 + outer_y2: 599 + overlay_border: True + overlay_position: 'top' + overlays: [] + padding: [0, 0, 0, 0] + padding_accepts_focus: True + padding_bottom: 0 + padding_left: 0 + padding_right: 0 + padding_top: 0 + pointer: 'arrow' + position: [50, 550] + resizable: 'h' + text: 'My Plot Title' + tools: [] + tooltip: None + underlays: [] + unified_draw: False + use_backbuffer: False + use_draw_order: True + use_selection: False + viewports: [] + visible: True + vjustify: 'center' + vpadding: 0 + width: 700 + window: None + x: 50 + x2: 749 + y: 550 + y2: 599