piotr | 4e65be9 | 2014-04-17 09:56:57 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* |
| 3 | * Copyright 2014 Piotr Krysik <pkrysik@elka.pw.edu.pl>. |
| 4 | * |
| 5 | * This is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3, or (at your option) |
| 8 | * any later version. |
| 9 | * |
| 10 | * This software is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this software; see the file COPYING. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #define USE_CXX (__cplusplus >= 201103) |
| 22 | |
| 23 | #include <vector> |
| 24 | #include <armadillo> |
| 25 | #include <string> |
| 26 | #include <boost/make_shared.hpp> |
| 27 | |
| 28 | #include "gnuplot-iostream.h" |
| 29 | |
| 30 | boost::shared_ptr<Gnuplot> current_figure; |
| 31 | |
| 32 | void imagesc(arma::mat & x){ |
| 33 | Gnuplot gp; |
| 34 | gp << "set palette rgb 3,2,2;"; |
| 35 | gp << "plot "; |
| 36 | gp << gp.file1d(x) << "matrix with image"; |
| 37 | gp << std::endl; |
| 38 | } |
| 39 | |
| 40 | void plot(arma::cx_mat & x, std::string title){ |
| 41 | arma::mat y = arma::abs(x); |
| 42 | if(current_figure.get()==NULL){ |
| 43 | current_figure = boost::make_shared<Gnuplot>(); |
| 44 | } |
| 45 | (*current_figure) << "plot "; |
| 46 | |
piotr | 7af92ca | 2014-07-08 16:38:42 +0200 | [diff] [blame] | 47 | (*current_figure) << current_figure->file1d(y) <<"title \'" << title << "\' with lines "; |
piotr | 4e65be9 | 2014-04-17 09:56:57 +0200 | [diff] [blame] | 48 | (*current_figure) << std::endl; |
| 49 | } |
| 50 | |
| 51 | void replot(arma::cx_mat & x, std::string title){ |
| 52 | arma::mat y = arma::abs(x); |
| 53 | if(current_figure.get()==NULL){ |
| 54 | current_figure = boost::make_shared<Gnuplot>(); |
| 55 | } |
| 56 | (*current_figure) << "replot "; |
| 57 | (*current_figure) << current_figure->file1d(y) <<"title \'" << title << "\' with lines "; |
| 58 | (*current_figure) << std::endl; |
| 59 | } |
| 60 | |
| 61 | template<typename T> |
| 62 | void plot(std::vector<T> & x){ |
| 63 | arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x); |
| 64 | plot(y,""); |
| 65 | } |
| 66 | |
| 67 | template<typename T> |
| 68 | void plot(std::vector<T> & x, std::string title){ |
| 69 | arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x); |
| 70 | plot(y,title); |
| 71 | } |
| 72 | |
| 73 | template<typename T> |
| 74 | void replot(std::vector<T> & x, std::string title){ |
| 75 | arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x); |
| 76 | replot(y,title); |
| 77 | } |
| 78 | |