MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/draw.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso, Raul Durand                   *
00004  * Copyright (C) 2009 Sergio Galindo                                    *
00005  *                                                                      *
00006  * This program is free software: you can redistribute it and/or modify *
00007  * it under the terms of the GNU General Public License as published by *
00008  * the Free Software Foundation, either version 3 of the License, or    *
00009  * any later version.                                                   *
00010  *                                                                      *
00011  * This program is distributed in the hope that it will be useful,      *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
00014  * GNU General Public License for more details.                         *
00015  *                                                                      *
00016  * You should have received a copy of the GNU General Public License    *
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00018  ************************************************************************/
00019 
00020 #ifndef MECHSYS_FEM_GRAPH_H
00021 #define MECHSYS_FEM_GRAPH_H
00022 
00023 // Std Lib
00024 #include <iostream>
00025 
00027 namespace MPL
00028 {
00029 
00030 inline void Header (std::ostream & os)
00031 {
00032     // header
00033     os << "from numpy import array, sqrt\n";
00034     os << "from pylab import figure, text, show, axis, plot, grid, savefig\n";
00035     os << "from pylab import matplotlib as MPL\n\n";
00036     os << "PH = MPL.path.Path\n";
00037     os << "PP = MPL.patches\n";
00038     os << "PC = MPL.patches.PathPatch\n\n";
00039 
00040     // colors
00041     os << "# colors\n";
00042     os << "pink    = (250/255.0,204/255.0,228/255.0)\n";
00043     os << "dred    = (163/255.0,  0/255.0,  0/255.0)\n";
00044     os << "lblue   = (217/255.0,228/255.0,255/255.0)\n";
00045     os << "lgreen  = (100/255.0,241/255.0,193/255.0)\n";
00046     os << "dblue   = ( 45/255.0,  0/255.0,160/255.0)\n";
00047     os << "orange  = (241/255.0,125/255.0,  0/255.0)\n";
00048     os << "dpink   = (170/255.0, 94/255.0,137/255.0)\n";
00049     os << "lyellow = (234/255.0,228/255.0,179/255.0)\n\n";
00050 
00051     // figure, axis, and data
00052     os << "# figure, axis, and data\n";
00053     os << "fig = figure()\n";
00054     os << "ax  = fig.add_subplot(111)\n";
00055     os << "dat = []\n\n";
00056 }
00057 
00058 inline void AddPatch (std::ostream & os, char const * EdgeColor="dblue", char const * FaceColor="lblue")
00059 {
00060     os << "if len(dat)>0:\n";
00061     os << "    cmd,vert = zip(*dat)\n";
00062     os << "    ph       = PH (vert, cmd)\n";
00063     os << "    pc       = PC (ph, edgecolor=" << EdgeColor << ", facecolor=" << FaceColor << ", linewidth=2)\n";
00064     os << "    ax.add_patch  (pc)\n\n";
00065 }
00066 
00067 inline void Show (std::ostream & os)
00068 {
00069     os << "grid()\n";
00070     os << "axis('scaled')\n";
00071     os << "show()\n";
00072 }
00073 
00074 inline void SaveFig (char const * FileKey, std::ostream & os)
00075 {
00076     String fn(FileKey);
00077     fn.append(".png");
00078     os << "grid()\n";
00079     os << "axis('scaled')\n";
00080     os << "savefig('"<< fn << "')\n";
00081 }
00082 
00083 }; // namespace MPL
00084 
00085 #endif // MECHSYS_FEM_GRAPH_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines