int main( int argc, char *argv[] ) { int i; // Parse and process command line arguments (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Initialize plplot plinit(); plfont( 2 ); // Make log plots using two different styles. i = 0; while ( x_labels[i] != NULL ) { plot1( 0, x_labels[i], y_labels[i], alty_labels[i], legend_texts[i], title_labels[i], line_labels[i] ); i++; } plend(); exit( 0 ); }
int main( int argc, char *argv[] ) { int i, j; plparseopts( &argc, argv, PL_PARSE_FULL ); plinit(); pladv( 0 ); plvpor( 0.0, 1.0, 0.0, 1.0 ); plwind( 0.0, 1.0, 0.0, 1.0 ); plcol0( 0 ); plbox( "", 1.0, 0, "", 1.0, 0 ); plscmap0n( 7 ); plscmap0( red, green, blue, 7 ); plschr( 0, 4.0 ); plfont( 1 ); for ( i = 0; i < 4; i++ ) { plcol0( i + 1 ); plfill( 4, px, py ); for ( j = 0; j < 4; j++ ) py [j] += 1.0 / 4.0; } plcol0( 0 ); for ( i = 0; i < 12; i++ ) plptex( sx [i], sy [i], 1.0, 0.0, 0.5, peace [i] ); plend(); exit( 0 ); }
bool plotNoiseStandardDeviation(const hoNDArray< std::complex<T> >& m, const std::vector<std::string>& coilStrings, const std::string& xlabel, const std::string& ylabel, const std::string& title, size_t xsize, size_t ysize, bool trueColor, hoNDArray<float>& plotIm) { try { size_t CHA = m.get_size(0); GADGET_CHECK_RETURN_FALSE(coilStrings.size() == CHA); hoNDArray<double> xd, yd, yd2; xd.create(CHA); yd.create(CHA); size_t c; for (c = 0; c < CHA; c++) { xd(c) = c+1; yd(c) = std::sqrt( std::abs(m(c, c)) ); } double maxY = Gadgetron::max(&yd); yd2 = yd; std::sort(yd2.begin(), yd2.end()); double medY = yd2(CHA / 2); // increase dot line to be 1 sigma ~= 33% double medRange = 0.33; if (maxY < medY*(1 + medRange)) { maxY = medY*(1 + medRange); } hoNDArray<unsigned char> im; im.create(3, xsize, ysize); Gadgetron::clear(im); plsdev("mem"); plsmem(im.get_size(1), im.get_size(2), im.begin()); plinit(); plfont(2); pladv(0); plvpor(0.15, 0.75, 0.1, 0.8); plwind(0, CHA+1, 0, maxY*1.05); plcol0(15); plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); std::string gly; getPlotGlyph(0, gly); // circle plstring(CHA, xd.begin(), yd.begin(), gly.c_str()); // draw the median line pllsty(1); double px[2], py[2]; px[0] = 0; px[1] = CHA+1; py[0] = medY; py[1] = medY; plline(2, px, py); pllsty(2); py[0] = medY*(1 - medRange); py[1] = medY*(1 - medRange); plline(2, px, py); py[0] = medY*(1 + medRange); py[1] = medY*(1 + medRange); plline(2, px, py); plmtex("b", 3.2, 0.5, 0.5, xlabel.c_str()); plmtex("t", 2.0, 0.5, 0.5, title.c_str()); plmtex("l", 5.0, 0.5, 0.5, ylabel.c_str()); // draw the legend std::vector<PLINT> opt_array(CHA), text_colors(CHA), line_colors(CHA), line_styles(CHA), symbol_numbers(CHA), symbol_colors(CHA); std::vector<PLFLT> symbol_scales(CHA), line_widths(CHA), box_scales(CHA, 1); std::vector<const char*> symbols(CHA); PLFLT legend_width, legend_height; std::vector<const char*> legend_text(CHA); std::vector<std::string> legends(CHA); size_t n; for (n = 0; n < CHA; n++) { opt_array[n] = PL_LEGEND_SYMBOL; text_colors[n] = 15; line_colors[n] = 15; line_styles[n] = (n % 8 + 1); line_widths[n] = 0.2; symbol_colors[n] = 15; symbol_scales[n] = 0.75; symbol_numbers[n] = 1; symbols[n] = gly.c_str(); std::ostringstream ostr; ostr << n+1 << ":" << coilStrings[n]; legends[n] = ostr.str(); legend_text[n] = legends[n].c_str(); } pllegend(&legend_width, &legend_height, PL_LEGEND_BACKGROUND, PL_POSITION_OUTSIDE | PL_POSITION_RIGHT, 0.02, // x 0.0, // y 0.05, // plot_width 0, // bg_color 15, // bb_color 1, // bb_style 0, // nrow 0, // ncolumn CHA, // nlegend &opt_array[0], 0.05, // text_offset 0.5, // text_scale 1.0, // text_spacing 0.5, // text_justification &text_colors[0], (const char **)(&legend_text[0]), NULL, // box_colors NULL, // box_patterns &box_scales[0], // box_scales NULL, // box_line_widths &line_colors[0], &line_styles[0], &line_widths[0], &symbol_colors[0], &symbol_scales[0], &symbol_numbers[0], (const char **)(&symbols[0]) ); plend(); outputPlotIm(im, trueColor, plotIm); } catch (...) { GERROR_STREAM("Errors happened in plotNoiseStandardDeviation(...) ... "); return false; } return true; }
template <typename T> EXPORTGTPLPLOT bool plotCurves(const std::vector<hoNDArray<T> >& x, const std::vector<hoNDArray<T> >& y, const std::string& xlabel, const std::string& ylabel, const std::string& title, const std::vector<std::string>& legend, const std::vector<std::string>& symbols, size_t xsize, size_t ysize, T xlim[2], T ylim[2], bool trueColor, bool drawLine, hoNDArray<float>& plotIm) { try { GADGET_CHECK_RETURN_FALSE(x.size()>0); GADGET_CHECK_RETURN_FALSE(y.size()>0); GADGET_CHECK_RETURN_FALSE(x.size() == y.size()); T minX = xlim[0]; T maxX = xlim[1]; T minY = ylim[0]; T maxY = ylim[1]; plsdev("mem"); hoNDArray<unsigned char> im; im.create(3, xsize, ysize); Gadgetron::clear(im); plsmem(im.get_size(1), im.get_size(2), im.begin()); plinit(); plfont(2); pladv(0); if (legend.size() == x.size()) { plvpor(0.11, 0.75, 0.1, 0.9); } else { plvpor(0.15, 0.85, 0.1, 0.9); } T spaceX = 0.01*(maxX - minX); T spaceY = 0.05*(maxY - minY); plwind(minX - spaceX, maxX + spaceX, minY - spaceY, maxY + spaceY); plcol0(15); plbox("bgcnst", 0.0, 0, "bgcnstv", 0.0, 0); // int mark[2], space[2]; //mark[0] = 4000; //space[0] = 2500; //plstyl(1, mark, space); size_t num = x.size(); size_t n; hoNDArray<double> xd, yd; // draw lines for (n = 0; n < num; n++) { size_t N = y[n].get_size(0); xd.copyFrom(x[n]); yd.copyFrom(y[n]); if (drawLine) { int c; getPlotColor(n, c); plcol0(c); pllsty(n % 8 + 1); plline(N, xd.begin(), yd.begin()); } std::string gly; if(symbols.size()>n) { gly = symbols[n]; } else getPlotGlyph(n, gly); plstring(N, xd.begin(), yd.begin(), gly.c_str()); } plcol0(15); plmtex("b", 3.2, 0.5, 0.5, xlabel.c_str()); plmtex("t", 2.0, 0.5, 0.5, title.c_str()); plmtex("l", 5.0, 0.5, 0.5, ylabel.c_str()); // draw the legend if (legend.size() == x.size()) { std::vector<PLINT> opt_array(num), text_colors(num), line_colors(num), line_styles(num), symbol_numbers(num), symbol_colors(num); std::vector<PLFLT> symbol_scales(num), line_widths(num), box_scales(num, 1); std::vector<std::string> glyphs(num); std::vector<const char*> symbols(num); PLFLT legend_width, legend_height; std::vector<const char*> legend_text(num); for (n = 0; n < num; n++) { int c; getPlotColor(n, c); getPlotGlyph(n, glyphs[n]); opt_array[n] = PL_LEGEND_SYMBOL | PL_LEGEND_LINE; text_colors[n] = 15; line_colors[n] = c; line_styles[n] = (n%8+1); line_widths[n] = 0.2; symbol_colors[n] = c; symbol_scales[n] = 0.75; symbol_numbers[n] = 1; symbols[n] = glyphs[n].c_str(); legend_text[n] = legend[n].c_str(); } pllegend(&legend_width, &legend_height, PL_LEGEND_BACKGROUND, PL_POSITION_OUTSIDE | PL_POSITION_RIGHT | PL_POSITION_TOP, 0.02, // x 0.0, // y 0.05, // plot_width 0, // bg_color 15, // bb_color 1, // bb_style 0, // nrow 0, // ncolumn num, // nlegend &opt_array[0], 0.05, // text_offset 0.35, // text_scale 1.0, // text_spacing 0.5, // text_justification &text_colors[0], (const char **)(&legend_text[0]), NULL, // box_colors NULL, // box_patterns &box_scales[0], // box_scales NULL, // box_line_widths &line_colors[0], &line_styles[0], &line_widths[0], &symbol_colors[0], &symbol_scales[0], &symbol_numbers[0], (const char **)(&symbols[0]) ); } plend(); outputPlotIm(im, trueColor, plotIm); } catch (...) { GERROR_STREAM("Errors happened in plotCurves(xlim, ylim) ... "); return false; } return true; }
int main( int argc, const char *argv[] ) { int i, j, dthet, theta0, theta1, theta; PLFLT just, dx, dy; static PLFLT x[500], y[500], per[5]; per[0] = 10.; per[1] = 32.; per[2] = 12.; per[3] = 30.; per[4] = 16.; // Parse and process command line arguments (void) plparseopts( &argc, argv, PL_PARSE_FULL ); // Initialize plplot plinit(); pladv( 0 ); // Ensure window has aspect ratio of one so circle is // plotted as a circle. plvasp( 1.0 ); plwind( 0., 10., 0., 10. ); // plenv(0., 10., 0., 10., 1, -2); plcol0( 2 ); // n.b. all theta quantities scaled by 2*M_PI/500 to be integers to avoid // floating point logic problems. theta0 = 0; dthet = 1; for ( i = 0; i <= 4; i++ ) { j = 0; x[j] = 5.; y[j++] = 5.; // n.b. the theta quantities multiplied by 2*M_PI/500 afterward so // in fact per is interpreted as a percentage. theta1 = (int) ( theta0 + 5 * per[i] ); if ( i == 4 ) theta1 = 500; for ( theta = theta0; theta <= theta1; theta += dthet ) { x[j] = 5 + 3 * cos( ( 2. * M_PI / 500. ) * theta ); y[j++] = 5 + 3 * sin( ( 2. * M_PI / 500. ) * theta ); } plcol0( i + 1 ); plpsty( ( i + 3 ) % 8 + 1 ); plfill( j, x, y ); plcol0( 1 ); plline( j, x, y ); just = ( 2. * M_PI / 500. ) * ( theta0 + theta1 ) / 2.; dx = .25 * cos( just ); dy = .25 * sin( just ); if ( ( theta0 + theta1 ) < 250 || ( theta0 + theta1 ) > 750 ) just = 0.; else just = 1.; plptex( ( x[j / 2] + dx ), ( y[j / 2] + dy ), 1.0, 0.0, just, text[i] ); theta0 = theta - dthet; } plfont( 2 ); plschr( 0., 1.3 ); plptex( 5.0, 9.0, 1.0, 0.0, 0.5, "Percentage of Sales" ); // Don't forget to call PLEND to finish off! plend(); exit( 0 ); }