This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/python/examples/plot.yap

40 lines
917 B
Plaintext
Raw Normal View History

2016-08-22 23:03:41 +01:00
:- [library(python)].
main :-
Plt = matplotlib.pyplot,
:= import( Plt ),
:= (
2016-08-25 18:10:33 +01:00
Plt.figure(figsize=(10,2.5)),
2016-08-22 23:03:41 +01:00
Plt.plot([1,2,3,4]),
Plt.ylabel(`some numbers`),
Plt.show()
).
2016-08-25 07:26:11 +01:00
2016-08-25 18:10:33 +01:00
main2 :-
:= ( import( numpy),
import( matplotlib.mlab),
import( matplotlib.pyplot) ),
NP = numpy,
Mlab = matplotlib.mlab,
Plt = matplotlib.pyplot,
% example data
mu := 100, % mean of distribution,
sigma := 15, % standard deviation of distribution,
x := mu + sigma * NP.random.randn(10000),
num_bins := 50,
% the histogram of the data
(n, bins, patches) := Plt.hist(x, num_bins, normed=1, facecolor= `green`, alpha=0.5),
% add a `best fit` line
y := Mlab.normpdf(bins, mu, sigma),
:= (Plt.plot(bins, y, `r--`),
Plt.xlabel(`Smarts`),
Plt.ylabel(`Probability`),
Plt.title(`Histogram of IQ: $\\mu=100$, $\\sigma=15$`),
% Tweak spacing to prevent clipping of ylabel,
Plt.subplots_adjust(left=0.15),
Plt.show()).