Plot cookbook project 📈

This is a brilliant idea!

Let’s make a Plot Cookbook :chart_with_upwards_trend::woman_cook:

  1. Post your favourite plot examples here
  2. I or someone else will create a Plot Cookbook repo and add to the package catalog
  3. Additional examples can be added by PR to the repo

https://github.com/Racket-Cookbooks/Plot-cookbook

Learn about the plot library here https://docs.racket-lang.org/plot

6 Likes

Wouldn't a wiki be better for this?
Possibly with links to code, but with pictures included.

1 Like

Seems like Scribble would be ideal. The code examples generate and include the pictures for you. Also the pictures will always be current with the library, which is huge in my opinion.

There would be marginally more friction to submitting examples (PRs I guess) but its nothing most Racketeers aren’t already doing.

1 Like

Maybe but I never worked out how to make a scribble wiki without creating a massive security risk.

The Plot Cookbook has launched!

Let's start simple!

The Plot Cookbook currently has a readme that links to one plot on http://pasterack.org/

Who will add a second one?

Once we have a small collection we can look at doing this as a wiki or documentation only package.

If you make a PR I will give you commit privileges :party_blob_gif:

2 Likes

We now have four contributions to the Racket Plot Cookbook!

Keep them coming and remember you can and should also submit plots to the Creative Racket Competition

best wishes
Stephen

PS Many thanks to @Laurent.O for the wonderful logo.

1 Like

Hi,
I prepared an example, where is used 1) numerical file 2) splines 3) latex. For scientists, it is a very common need. I used a file with data. Must I add this file or not? Its size is 4.8Kb.

#lang racket
(require plot latex-pict)                         ; latex-pict is modeule to use latex
(require simple-polynomial/private/poly-smooth)   ; to make specific splines
(require simple-polynomial/fit)                   ; to make simple splines
(plot-new-window? #t)                             ; to show plot in separate window. #f is opposite
(current-directory (current-directory))           ; the current directory is the directory of rkt file 
;(current-directory "/path/to/directory")         ; for specific directory 
(define F1 (call-with-input-file* "F1.txt"
  (λ (in)
    (for/list ([l (in-lines in)])
       (map string->number (string-split l))))))  ; Fi.txt contains two column of number separated by space - x y.
                                                  ; F1 contains the same numbers but pared like (x y)
                                                  ; to see F1 use (displayln F1)
;(define spF1 (points->spline-evaluator F1))      ; make smoothed data function for plot F1, simple spline
(define spF1
  (points->spline-evaluator
   ((make-least-squares-point-smoother 7 4 0) F1))) ; make smoothed data function for plot F1, regulated form of spline

(parameterize
    [(plot-y-ticks (linear-ticks #:number 2)); Number of ticks in y axis
    (plot-line-width 4)                      ; width of axes
    (plot-font-size 26)                      ; font size fpr plot
    (plot-font-family 'modern)               ; all possibilies are here https://docs.racket-lang.org/draw/font_.html 
    (plot-tick-size 14)                      ; size of ticks
    (plot-background-alpha 0)                ; full transparancy is for 0
    (plot-x-far-axis? #t)                    ; #f - removes upper boundary of frame
    (plot-y-far-axis? #t)                    ; #f - removes right boundary of frame
    ]
  (plot
   (list                                     ; use list for more than single function to plot
    (function spF1 0 100 #:color "Royal Blue" #:width 5) ; the first function to plot
    ; all colors names are here https://docs.racket-lang.org/draw/color-database___.html
    (point-label #(1 .1) "a)" #:point-size 0))           ; second figure to plot is label a) at point (1 .1)
        ; below are options to plot at whole
        #:title (tex-math "\\mathcal{E}^{\\mathrm{gg}}_2 /\\mathcal{E}_{\\mathrm{id}}" #:scale 5) ; title of figure
                                             ;; in the latex form. Use double backslash \\ instead of single one \ 
                                             ;; scale regulates size of fonts. \Large, \Huge does not work
        #:width 800 #:height 800             ; size of plot
        #:y-min 0 #:y-max 1.5                ; range for y axes
        #:out-file "f1.pdf"                  ; save file in pdf format
        ;#:out-file "f1.png"                 ; save file in png format
        #:y-label ""                         ; there is no label at y axes
        #:x-label (tex-math "a\\ \\mathrm{(nm)}" #:scale 5)) ; x label by using latex 
  )

The plot is below

1 Like

Yes add everything needed to do the example.

I think it might me worth creating a folder to keep everything from a single example together, and just have thumbnails in the readme.md file

Best regards

Stephen

All files are here Example-1 - Google Drive

Can you do a pull request on the repo?

Sorry, I never did this :slight_smile: . How can I do it?

1 Like

Sorry. I shouldn’t assume everyone knows about pull requests, git, version control and git repository hosting services like github.

It sounds like a lot of weird jargon but - bear with me - it is actually quite useful. There was I time when I did not know about this and I’m grateful for the people who explained it to me.

Git is version control software that makes it easier for groups to collaborate on software projects consisting of many source code files. You might use the version functions in Microsoft word or similar. This is similar but works with many more people and documents (source files) at the same time.

Git is not perfect and a subject of research to make it better. Design and usability are important. (I have a sticker on my laptop ‘usability is a clinical safety issue’) despite the problems with git it remains one of the best tools we have to let many people collaborate on software projects.

There are a number of git hosting services that help make it easier to use by providing a web interface.

Racket uses GitHub, but there are others like GitLAB.

In git, a collection of files being managed as a group is called a repository.

The way you propose a change is to make a pull request. Services like GitHub let you use a web interface to create pull requests. You don’t normally use the web interface but it is fine for adding files and updating markdown documents because GitHub has markdown editing support.

So that is the background. To actually do it

  1. Got to GitHub.com and make a free account
  2. Go to GitHub - Racket-Cookbooks/Plot-cookbook: Plot Cookbook
  3. Click create new file
  4. Type examples/f1/f1.md
  5. On the first line type# F1
  6. On the second line type a description
  7. Save the file

There will be some stuff about not having write access; the outcome is you have taken a copy of the plot-cookbook in your GitHub account

The copy will be a branch normally called patch-1 (The first time), and will be in the top left of your copy of the Plot-cookbook repository.

  1. You can click on the examples/f1/ folder and drag and drop the other files you need to include.
  2. Click the green create pull request button
  3. Follow the steps, include a description submit and you are done.

Now I’ve written it out it seems like a lot of steps.

If I do this one can you check it for me?

Best regards

Stephen

@JoePass I've added it.

check it out at https://github.com/Racket-Cookbooks/Plot-cookbook

Thank you for your contribution.

best regards,
Stephen

Thank you for your explanation. I used Bitbucket (and I have an account in GitHub, but never used it), but only for my latex projects, for my own papers. I know a little bit how to work with git, but exclusively with my projects, like making commit and putting new files in the project. I'd like to make two examples more - 1) to add text out of the plot, like scale factor of axes, and 2) to make an insert to the plot. For my special case, it is enough for my scientific publications. My question now - must I first to put examples here or directly put them in the GitHub project by using your rules above?

1 Like

Hi Joe,

On Github the usual steps are:

  1. Go to the repo you want to contribute to.
    In this case: GitHub - Racket-Cookbooks/Plot-cookbook: Plot Cookbook

  2. Click "Fork".


    This makes a copy of the repo. You can find it at:

https://github.com/joepass

The idea is that one can experiment with the copy with being nervous anything breaks.

Now there are two options:
a) Either work directly in Github
b) or clone the repo to you own computer.

For small changes such as adding a file or two the simplest might be a).

First find the folder you want to add a file to, then click the "Add File" button:


Either upload a file or edit one in the browser.

When you are done, fill out the commit message at the bottom of the screen.

The status message will show that your copy is now 1 commit ahead of the original repo.

If you want to check that everything looks right, click the commit and read the diff.
If everything looks okay, then it is time to click the "Contribute" button and make a pull request.
The owner of the repo will get a message that as pull request (PR) is ready, and he will manually
merge into the original repo.

The alternative to the adding the files on Github directly is to clone your Github copy to your computer.
That's done by clicking the "Code" button to find the url of your git copy.

You can now work on the copy the same way you do when you are using BitBucket.
When you have made the changes you want, you use git add filename to add all new and changed files.
A commit is made with commit -m "I added some files" . Finally use git push` to copy the changes back to Github.
The changes go to your copy, so you can check that everything looks fine on Gihub, before clicking the "Contribute" button.

As always: there are many ways of using git and Github, so the above describes only one way.

2 Likes

Here is fine - I am happy to upload them for you.

Thank you for your contributions, they are greatly appreciated.

Best regards

Stephen

Looking much nicer now - thank you to all the contributors

https://github.com/Racket-Cookbooks/Plot-cookbook

1 Like

Here is a second example with the numerical data file, spline, latex, and text outside of plot to mark scale of y-axes: Example-2 - Google Drive.

The third example is inserting figure f2 to figure f1: Example-3 - Google Drive.

These three examples cover all I need to produce fine figures for scientific papers. Before, I used pgfplots with latex. Now can use racket.

Could you put them into the cookbook or I will put them by myself?

1 Like

I've done f2. I'm happy for you to do f3.

Need to fix the caption/description for f2.

Can you set the plot-background-alpha to 1? On github with a dark background we can't see the labels, which are the important parts of this examples