[petsc-users] Drawing a line plot with two lines

Smit Thijs thijs.smit at hest.ethz.ch
Fri Apr 14 01:57:49 CDT 2023


Hi All,

I am trying to plot a loglog plot with two lines, one for my error and one with a slope of 1. Plotting only the error or only the slope of 1 works fine, but I like both lines in the same plot (that doesn't work till now). Does somebody know how to solve this? Find a code snipet below:

PetscDraw     draw;
PetscDrawLG   lg;
PetscDrawAxis axis;
PetscReal     xc, yc;
PetscDrawCreate(PETSC_COMM_SELF, NULL, "Log(Error) vs Log(dx)", PETSC_DECIDE, PETSC_DECIDE, PETSC_DRAW_HALF_SIZE, PETSC_DRAW_HALF_SIZE, &draw);
PetscDrawSetFromOptions(draw);
PetscDrawLGCreate(draw, 2, &lg);
PetscDrawLGSetUseMarkers(lg, PETSC_TRUE);
PetscDrawLGGetAxis(lg, &axis);
PetscDrawAxisSetLabels(axis, NULL, "Log(dx)", "Log(Error)");

for loop {
xc = PetscLog10Real(dx);
yc = PetscLog10Real(error);
PetscDrawLGAddPoint(lg, &xc, &yc); // to plot the error
PetscDrawLGAddPoint(lg, &xc, &xc); // to plot line with slope 1
PetscDrawLGDraw(lg);
}

PetscDrawSetPause(draw, -2);
PetscDrawLGDestroy(&lg);
PetscDrawDestroy(&draw);

Best regards,

Thijs Smit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230414/72e6691b/attachment.html>


More information about the petsc-users mailing list