blob: 9f8fcd338d62d2a224bb6835e1959b5dc050b110 [file] [log] [blame]
piotr4e65be92014-04-17 09:56:57 +02001/* -*- 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
30boost::shared_ptr<Gnuplot> current_figure;
31
32void 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
40void 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
47 (*current_figure) << current_figure->file1d(y) <<"title \'" << titl
48 e << "\' with lines ";
49 (*current_figure) << std::endl;
50}
51
52void replot(arma::cx_mat & x, std::string title){
53 arma::mat y = arma::abs(x);
54 if(current_figure.get()==NULL){
55 current_figure = boost::make_shared<Gnuplot>();
56 }
57 (*current_figure) << "replot ";
58 (*current_figure) << current_figure->file1d(y) <<"title \'" << title << "\' with lines ";
59 (*current_figure) << std::endl;
60}
61
62template<typename T>
63void plot(std::vector<T> & x){
64 arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
65 plot(y,"");
66}
67
68template<typename T>
69void plot(std::vector<T> & x, std::string title){
70 arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
71 plot(y,title);
72}
73
74template<typename T>
75void replot(std::vector<T> & x, std::string title){
76 arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
77 replot(y,title);
78}
79