Skip to content

Commit 4c4882c

Browse files
committed
Bugfixes; funcionando sistema básico
1 parent 2b5e358 commit 4c4882c

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

src/main.cc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@ int main()
1616
float xCoord = (float) (i -100)/10;
1717

1818
matrix_x.add(i, 1, xCoord);
19+
matrix_x.add(i, 2, xCoord); //Segundo plotter
20+
matrix_x.add(i, 3, xCoord);
21+
1922
matrix_y.add(i, 1, sin(2*xCoord) + cos(xCoord));
23+
matrix_y.add(i, 2, cos(2*xCoord) + sin(xCoord)); //Segundo plotter em Y. Alterando dados
24+
matrix_y.add(i, 3, 1);
2025
}
2126

2227
//Instanciando plotter
2328
//MatrixPlot matrixplot = MatrixPlot(2, 2); //Define subplot Cols; subplot Rows;
2429

2530
MatrixPlot matrixplot = MatrixPlot();
31+
matrixplot.setAutoRange(false);
32+
33+
matrixplot.SetRange('x', -10, 10);
34+
matrixplot.SetRange('y', -2, 6);
35+
2636
matrixplot.plot1d(matrix_x, matrix_y);
2737
cout << "Depois do plot" << endl;
28-
//Matrix matrix_box = Matrix(10,2);
2938

30-
//matrixplot.plotbox(matrix);
39+
matrixplot.saveToFile("teste.eps");
3140

32-
//Plotando matrix 1d
33-
/*
34-
matrixplot.plot1d(matrix, 0); //Plota e define o indice do subplot
35-
matrixplot.plot1d(matrix, 1);
36-
matrixplot.plot1d(matrix, 2);
37-
matrixplot.plot1d(matrix, 3);
38-
*/
3941
matrixplot.Run();
4042

4143
return 0;

src/matrix-plot.cc

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "matrix-plot.h"
2121
#include "MatrixPlotWindow.h"
22-
#include <mgl2/fltk.h>
2322

2423
MatrixPlot::MatrixPlot(int subplotCols, int subplotRows)
2524
{
@@ -179,22 +178,39 @@ void MatrixPlot::plot1d(Matrix & xMatrix, Matrix & yMatrix){
179178

180179
//Subplotagem
181180

182-
this->SubPlot(
181+
/*this->SubPlot(
183182
this->subplotCols,
184183
this->subplotRows,
185184
0, "");
186185
187-
this->Axis("xy");
186+
this->Axis("xy");*/
188187

189-
if (this->autoRange)
188+
string color = "";
189+
switch (subplotIndex)
190+
{
191+
case 0:
192+
color = "r";
193+
break;
194+
case 1:
195+
color = "g";
196+
break;
197+
case 2:
198+
color = "b";
199+
break;
200+
}
201+
202+
if (this->autoRange && subplotIndex == (subplotAmount-1))
190203
{
191204
this->SetRange('x', matrixRange.x_min, matrixRange.x_max);
192205
this->SetRange('y', matrixRange.y_min, matrixRange.y_max);
193206
}
194207

195-
this->Plot(matrix_X_coordinates, matrix_Y_coordinates);
208+
this->Axis("xy");
209+
this->Plot(matrix_X_coordinates, matrix_Y_coordinates, color.c_str());
210+
this->AddLegend("Plot",color.c_str());
196211
}
197212

213+
this->Legend();
198214

199215
}
200216

@@ -282,9 +298,15 @@ void MatrixPlot::plotbox(Matrix & referenceMatrix, int subplotIndex)
282298
}
283299

284300
this->Plot(matrix_X_coordinates, matrix_Y_coordinates);
301+
285302
}
286303

287304
void MatrixPlot::setAutoRange(bool option)
288305
{
289306
this->autoRange = option;
290307
}
308+
309+
void MatrixPlot::saveToFile(const string filename)
310+
{
311+
this->WriteEPS(filename.c_str());
312+
}

src/matrix-plot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class MatrixPlot : public mglFLTK
3636
void plotbox(Matrix &, int = 0);
3737

3838
void setAutoRange(bool);
39+
void saveToFile(const string);
3940

4041
private:
4142
bool autoRange;

0 commit comments

Comments
 (0)