File: plplotcanvas_demo.c

package info (click to toggle)
plplot 5.10.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,280 kB
  • ctags: 13,512
  • sloc: ansic: 83,001; xml: 27,081; ada: 18,878; cpp: 15,966; tcl: 11,651; python: 7,075; f90: 7,058; ml: 6,974; java: 6,665; perl: 5,029; sh: 2,210; makefile: 199; lisp: 75; sed: 25; fortran: 7
file content (109 lines) | stat: -rw-r--r-- 3,761 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// demo.c - Demonstrates the simplest use of the plplot canvas widget with gtk.
//
//  Copyright (C) 2004, 2005 Thomas J. Duck
//  All rights reserved.
//
//  Thomas J. Duck <tom.duck@dal.ca>
//  Department of Physics and Atmospheric Science,
//  Dalhousie University, Halifax, Nova Scotia, Canada, B3H 3J5
//
//  $Author: airwin $
//  $Revision: 11289 $
//  $Date: 2010-10-29 13:44:17 -0700 (Fri, 29 Oct 2010) $
//  $Name$
//
//
// NOTICE
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//  MA  02110-1301  USA
//

#include <plplotcanvas.h>
#include <gtk/gtk.h>

// The width and height of the plplot canvas widget
#define WIDTH     1000 // 500
#define HEIGHT    600  // 300

// Delete event callback
gint delete_event_local( GtkWidget *widget, GdkEvent *event, gpointer data )
{
    return FALSE;
}

// Destroy event calback
void destroy_local( GtkWidget *widget, gpointer data )
{
    gtk_main_quit();
}


int main( int argc, char *argv[] )
{
    PlplotCanvas* canvas;
    GtkWidget   *window;

    // Parse the options
    plparseopts( &argc, (const char **) argv, PL_PARSE_FULL );

    // The data to plot
    double x[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    double y[11] = { 0, 0.1, 0.4, 0.9, 1.6, 2.6, 3.6, 4.9, 6.4, 8.1, 10 };

    // Initialize gtk and the glib type system
    gtk_init( &argc, &argv );
    g_type_init();

    // Create the canvas and set its size; during the creation process,
    // the gcw driver is loaded into plplot, and plinit() is invoked.
    //
    canvas = plplot_canvas_new( TRUE );
    plplot_canvas_set_size( canvas, WIDTH, HEIGHT );

    // Create a new window and stuff the canvas into it
    window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
    gtk_container_set_border_width( GTK_CONTAINER( window ), 10 );
    gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( canvas ) );

    // Connect the signal handlers to the window decorations
    g_signal_connect( G_OBJECT( window ), "delete_event",
        G_CALLBACK( delete_event_local ), NULL );
    g_signal_connect( G_OBJECT( window ), "destroy", G_CALLBACK( destroy_local ), NULL );

    // Display everything
    gtk_widget_show_all( window );

    // Draw on the canvas with Plplot
    plplot_canvas_adv( canvas, 0 );                                   // Advance to first page
    plplot_canvas_col0( canvas, 15 );                                 // Set color to black
    plplot_canvas_wid( canvas, 2 );                                   // Set the pen width
    plplot_canvas_vsta( canvas );                                     // Set the viewport
    plplot_canvas_wind( canvas, 0., 10., 0., 10. );                   // Set the window
    plplot_canvas_box( canvas, "bcnst", 0., 0, "bcnstv", 0., 0 );     // Set the box
    plplot_canvas_lab( canvas, "x-axis", "y-axis", "A Simple Plot" ); // Draw some labels

    // Draw the line
    plplot_canvas_col0( canvas, 1 ); // Set the pen color
    plplot_canvas_line( canvas, 11, x, y );

    // Advancing the page finalizes this plot
    plplot_canvas_adv( canvas, 0 );

    // Start the gtk main loop
    gtk_main();
    return 0;
}