aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Pan <xyz@flylightning.xyz>2025-04-24 23:03:21 -0700
committerXiao Pan <xyz@flylightning.xyz>2025-04-24 23:03:21 -0700
commitcefa2377548300140e54422d9f0fb88586fb9629 (patch)
tree41ab97ef9730d8342105c618cf691ed413a0eaf3
parent696c9b98119d10e08cbb1069fa0cf780df6b73dc (diff)
better plot
-rw-r--r--remote_plot.c136
1 files changed, 34 insertions, 102 deletions
diff --git a/remote_plot.c b/remote_plot.c
index 3226b20..54338aa 100644
--- a/remote_plot.c
+++ b/remote_plot.c
@@ -1,8 +1,9 @@
// references:
// https://api.libssh.org/stable/libssh_tutorial.html
// https://api.libssh.org/stable/libssh_tutor_guided_tour.html
-// plplot example 17
-// plplot example ext-cairo-test.c
+// http://plplot.org/documentation.php
+// http://plplot.org/examples.php
+// plplot example 0 and ext-cairo-test.c
// https://docs.gtk.org/gtk4/class.DrawingArea.html
// https://www.gtk.org/docs/getting-started/hello-world/
// https://gitlab.gnome.org/GNOME/gtk/-/blob/main/demos/print-editor/print-editor.c
@@ -170,14 +171,9 @@ const char *checkbutton_names[]={
"0x695_BMS_Section_1_Temp"
};
-// Variables for holding error return info from PLplot
-static PLINT pl_errcode;
-static char errmsg[160];
-
typedef struct {
ssh_session session;
sftp_session sftp;
- PLINT id1;
PLFLT t[LEN];
PLFLT volt[LEN][VOLTLEN];
PLFLT temp[LEN][TEMPLEN];
@@ -348,6 +344,9 @@ int verify_knownhost(ssh_session session)
return 0;
}
+// http://plplot.org/documentation.php
+// http://plplot.org/examples.php
+// plplot example 0 and ext-cairo-test.c
static void draw_function (GtkDrawingArea *area,
cairo_t *cr,
int width,
@@ -357,108 +356,41 @@ static void draw_function (GtkDrawingArea *area,
//printf("draw begin\n");
DATA *data=user_data;
- PLINT autoy, acc;
- PLFLT ymin, ymax, xlab, ylab;
- PLFLT tmin, tmax, tjump;
- PLINT colbox, collab, colline[4], styline[4];
- PLCHAR_VECTOR legline[4];
-
- // If db is used the plot is much more smooth. However, because of the
- // async X behaviour, one does not have a real-time scripcharter.
- // This is now disabled since it does not significantly improve the
- // performance on new machines and makes it difficult to use this
- // example non-interactively since it requires an extra pleop call after
- // each call to plstripa.
- //
- //plsetopt("db", "");
- //plsetopt("np", "");
-
- // User sets up plot completely except for window and data
- // Eventually settings in place when strip chart is created will be
- // remembered so that multiple strip charts can be used simultaneously.
- //
-
- // Specify some reasonable defaults for ymin and ymax
- // The plot will grow automatically if needed (but not shrink)
-
- ymin = -0.1;
- ymax = 0.1;
-
- // Specify initial tmin and tmax -- this determines length of window.
- // Also specify maximum jump in t
- // This can accomodate adaptive timesteps
-
- tmin = 0.;
- tmax = 10.;
- tjump = 0.3; // percentage of plot to jump
-
- // Axes options same as plbox.
- // Only automatic tick generation and label placement allowed
- // Eventually I'll make this fancier
-
- colbox = 1;
- collab = 3;
- styline[0] = colline[0] = 2; // pens color and line style
- styline[1] = colline[1] = 3;
- styline[2] = colline[2] = 4;
- styline[3] = colline[3] = 5;
-
- legline[0] = "voltage"; // pens legend
- legline[1] = "not_used";
- legline[2] = "not_used";
- legline[3] = "not_used";
-
- xlab = 0.; ylab = 0.25; // legend position
-
- autoy = 1; // autoscale y
- acc = 1; // don't scrip, accumulate
+ PLFLT y[LEN];
+ PLFLT xmin = data->t[0], xmax = data->t[LEN-1], ymin = 0, ymax = 6.;
- // Initialize plplot
+ for(int i=0;i<LEN;i++)
+ y[i]=data->volt[i][0];
plsdev( "extcairo" );
- plinit();
- pl_cmd( PLESC_DEVINIT, cr );
-
- pladv( 0 );
- plvsta();
-
- // Register our error variables with PLplot
- // From here on, we're handling all errors here
-
- plsError( &pl_errcode, errmsg );
-
- plstripc( &(data->id1), "bcnst", "bcnstv",
- tmin, tmax, tjump, ymin, ymax,
- xlab, ylab,
- autoy, acc,
- colbox, collab,
- colline, styline, legline,
- "t", "", "Strip chart demo" );
-
- if ( pl_errcode )
- {
- fprintf( stderr, "%s\n", errmsg );
- exit( 1 );
- }
-
- // Let plplot handle errors from here on
- plsError( NULL, NULL );
+ // change to white background and black foreground, and gray color palette
+ // http://plplot.org/docbook-manual/plplot-html-5.15.0/color.html
+ // seems should be put before plinit; or need pladv(), plvpor(), plwind() for a new picture?
+ // more see example 16
+ // http://plplot.org/examples.php?demo=16
+ // /usr/share/plplot5.15.0/examples/c/x16c.c
+ plspal0("cmap0_black_on_white.pal");
+ plspal1("cmap1_gray.pal", 1);
- autoy = 0; // autoscale y
- acc = 1; // accumulate
-
- for(int i=0;i<LEN;i++)
- {
- //printf("t%d %f\n",i,data->t[i]);
- //printf("buffer%d %f\n",i,data->buffer[i]);
- plstripa( data->id1, 0, data->t[i], data->volt[i][0]);
- }
+ // Initialize plplot
+ plinit();
+ pl_cmd( PLESC_DEVINIT, cr );
- //printf("before pl free\n");
- plstripd( data->id1 );
+ // Create a labelled box to hold the plot.
+ plenv(xmin, xmax, ymin, ymax, 0, 0);
+ pllab("Time (s)","Voltage (V)","Time vs. Voltage");
+ // Plot the data that was prepared above.
+ // plstring for scatter
+ // #(NNN) is Hershey font code, more see example 5, 6, 21
+ // #(727) is centred X symbol; other maybe useful codes: #(728)
+ // hershey font code see http://plplot.org/examples.php?demo=07 ?
+ plstring(LEN, data->t, y, "#(727)");
+ // pline for line
+ plline(LEN, data->t, y);
+
+ // Close PLplot library
plend();
- //printf("draw done\n");
}
static void print_data (GtkWidget *widget, gpointer user_data)