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

Matthew Knepley knepley at gmail.com
Fri Apr 14 06:59:07 CDT 2023


On Fri, Apr 14, 2023 at 2:58 AM Smit Thijs <thijs.smit at hest.ethz.ch> wrote:

> 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
>

Here is want an array of points, one for each curve:

  https://petsc.org/main/manualpages/Draw/PetscDrawLGAddPoint/

  Thanks,

     Matt


> PetscDrawLGAddPoint(lg, &xc, &xc); // to plot line with slope 1
>
> PetscDrawLGDraw(lg);
> }
>
> PetscDrawSetPause(draw, -2);
>
> PetscDrawLGDestroy(&lg);
>
> PetscDrawDestroy(&draw);
>
>
>
> Best regards,
>
>
>
> Thijs Smit
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230414/85598d8b/attachment.html>


More information about the petsc-users mailing list