forked from highoover/LaTeX_From_Birth_Death
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2a8984
commit 982ab08
Showing
24 changed files
with
6,564 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
\NeedsTeXFormat{LaTeX2e} | ||
\ProvidesPackage{2d_plot/2d_plot} | ||
\RequirePackage{expl3, l3sys-shell} | ||
\RequirePackage{xparse} | ||
|
||
|
||
|
||
\ExplSyntaxOn | ||
% plot data's id(counter) | ||
\newcounter{gnu@plot@data@counter} | ||
\newcommand{\gnu@data@fullname}{} | ||
\bool_new:N \Change@Precise@Once | ||
|
||
|
||
%%%%% the relative path there = path of '.tex' source file | ||
%%%%% Bug: \file_if_exist can't check if a dir is exsits | ||
\sys_shell_now:n {mkdir~ ./2d_plot/gnuplot_output_data} | ||
|
||
|
||
|
||
% ---------------------------------------------------------------------- | ||
% 1.precision of plot | ||
% ---------------------------------------------------------------------- | ||
\NewDocumentCommand\NormalPlotPrecise{O{once}m}{ | ||
\str_if_eq:nnTF {#1}{once}{ | ||
\bool_set_true:N \Change@Precise@Once | ||
}{\relax} | ||
\sys_shell_now:n {sed~ -i~ "3s|set~ samples~ .*|set~ samples~ #2|"~ ./2d_plot/Scripts/data_gen.gp} | ||
} | ||
\NewDocumentCommand\ParamPlotPrecise{O{once}m}{ | ||
\str_if_eq:nnTF {#1}{once}{ | ||
\bool_set_true:N \Change@Precise@Once | ||
}{\relax} | ||
\sys_shell_now:n {sed~ -i~ "3s|set~ samples~ .*|set~ samples~ #2|"~ ./2d_plot/Scripts/param_data_gen.gp} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
% ---------------------------------------------------------------------- | ||
% 2.coordinate basic components | ||
% ---------------------------------------------------------------------- | ||
% Example: \ShowPoint[radius=3pt, color=blue, opacity=.5] {(1, 1); (2, 2)}[text1; text2; text3][text style]; | ||
\keys_define:nn { __Point__ }{ | ||
type .tl_set:N = \l__Point_type, | ||
type .initial:n = { circle }, | ||
radius .dim_set:N = \l__Point_radius, | ||
radius .initial:n = { 1pt }, | ||
color .tl_set:N = \l__Point_color, | ||
color .initial:n = { black }, | ||
opacity .tl_set:N = \l__Point_opacity, | ||
opacity .initial:n = { 1 } | ||
} | ||
\NewDocumentCommand\ShowPoint{ O{}mO{}O{} }{ | ||
% use the following to initial options each times if not in local group | ||
% \keys_set:nn { __Point__ } {color=black, opacity=1, type=circle, radius=1pt} | ||
\group_begin: | ||
\keys_set:nn { __Point__ } { #1 } | ||
\seq_set_split:Nnn \l__point_param_ii_seq { ; }{#2} | ||
\seq_set_split:Nnn \l__point_param_iii_seq { ; }{#3} | ||
% ==> previous showpoint code without annotate=ion | ||
% \seq_map_inline:Nn \l__point_param_ii_seq{ | ||
% \fill[color=\l__Point_color, opacity=\l__Point_opacity] | ||
% ##1 \l__Point_type(\dim_use:N \l__Point_radius); | ||
% } | ||
\int_step_inline:nnnn {1}{1}{\seq_count:N \l__point_param_ii_seq}{ | ||
\fill[color=\l__Point_color, opacity=\l__Point_opacity] | ||
\seq_item:Nn \l__point_param_ii_seq{##1} \l__Point_type(\dim_use:N \l__Point_radius) | ||
node[#4]{\seq_item:Nn \l__point_param_iii_seq{##1}}; | ||
} | ||
\group_end: | ||
} | ||
|
||
% Example: \ShowGrid[color=red, thick]{(-5, -5); (5, 5)} | ||
\NewDocumentCommand\ShowGrid{ O{color=gray, very~ thin, step=1}m }{ | ||
\seq_set_split:Nnn \l__grid_param_ii_seq { ; }{#2} | ||
\draw[#1] \seq_item:Nn \l__grid_param_ii_seq{1} grid \seq_item:Nn \l__grid_param_ii_seq{2}; | ||
} | ||
|
||
% Example: \ShowAxis {(0, -8); (0, 8)} | ||
\NewDocumentCommand\ShowAxis{ O{color=black}m }{ | ||
\seq_set_split:Nnn \l__axis_param_ii_seq { ; }{#2} | ||
\draw[->, #1] \seq_item:Nn \l__axis_param_ii_seq{1} -- \seq_item:Nn \l__axis_param_ii_seq{2}; | ||
} | ||
|
||
% Example:\ShowIntersecions{exp; ellipse}{2} | ||
\NewDocumentCommand\ShowIntersecions{ omm }{ | ||
\seq_set_split:Nnn \l__intersection_num_seq { ; }{#2} | ||
% get all intersections | ||
\path[name~ intersections={of=\seq_item:Nn \l__intersection_num_seq{1}~ and~ \seq_item:Nn \l__intersection_num_seq{2}}]; | ||
% show all intersections by \ShowPoint | ||
\int_step_inline:nnnn {1}{1}{#3}{ | ||
\ShowPoint[#1]{(intersection-##1)} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
% ---------------------------------------------------------------------- | ||
% 3.2d function plot | ||
% ---------------------------------------------------------------------- | ||
% normal 2d function | ||
\NewDocumentCommand\NormalPlot{O{color=black}O{-5:5}m}{ | ||
% step id of data | ||
\stepcounter{gnu@plot@data@counter} | ||
% sed gnuplot scripts | ||
\sys_shell_now:n {sed~ -i~ "8s|set~ xr~ .*|set~ xr~ [#2]|"~ ./2d_plot/Scripts/data_gen.gp} | ||
\sys_shell_now:n {sed~ -i~ "7s|f(x)~ =~ .*|f(x)~ =~ #3|"~ ./2d_plot/Scripts/data_gen.gp} | ||
\sys_shell_now:n {gnuplot~ ./2d_plot/Scripts/data_gen.gp} | ||
% data file rename | ||
\renewcommand{\gnu@data@fullname}{data_gen_\the\value{gnu@plot@data@counter}.table} | ||
\cs_generate_variant:Nn \sys_shell_mv:nn {nx} | ||
\sys_shell_mv:nx {./2d_plot/gnuplot_output_data/data_gen.table}{./2d_plot/gnuplot_output_data/\gnu@data@fullname} | ||
% draw function graph according to data in file | ||
\draw[#1] plot[smooth] file {./2d_plot/gnuplot_output_data/\gnu@data@fullname}; | ||
% reset boolean and set to default precise | ||
\bool_if:NTF \Change@Precise@Once{ | ||
\NormalPlotPrecise{500} | ||
}{\relax} | ||
} | ||
|
||
% parametric 2d function | ||
\NewDocumentCommand\ParamPlot{O{color=black}O{-5:5}m}{ | ||
% step id of data | ||
\stepcounter{gnu@plot@data@counter} | ||
% sed gnuplot scripts | ||
\sys_shell_now:n {sed~ -i~ "8s|set~ trange~ .*|set~ trange~ [#2]|"~ ./2d_plot/Scripts/param_data_gen.gp} | ||
\sys_shell_now:n {sed~ -i~ "9s|plot~ .*|plot~ #3|"~ ./2d_plot/Scripts/param_data_gen.gp} | ||
\sys_shell_now:n {gnuplot~ ./2d_plot/Scripts/param_data_gen.gp} | ||
% data file rename | ||
\renewcommand{\gnu@data@fullname}{param_data_gen_\the\value{gnu@plot@data@counter}.table} | ||
\cs_generate_variant:Nn \sys_shell_mv:nn {nx} | ||
\sys_shell_mv:nx {./2d_plot/gnuplot_output_data/param_data_gen.table}{./2d_plot/gnuplot_output_data/\gnu@data@fullname} | ||
% draw function graph according to data in file | ||
\draw[#1] plot[smooth] file {./2d_plot/gnuplot_output_data/\gnu@data@fullname}; | ||
% reset boolean and set to default | ||
\bool_if:NTF \Change@Precise@Once{ | ||
\ParamPlotPrecise{500} | ||
}{\relax} | ||
} | ||
\ExplSyntaxOff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
set table "./2d_plot/gnuplot_output_data/data_gen.table" | ||
set format "%.5f" | ||
set samples 500 | ||
|
||
|
||
# specific a 2d function | ||
f(x) = 3*sin(1/x) | ||
set xr [-6:-1] | ||
plot f(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
set table "./2d_plot/gnuplot_output_data/param_data_gen.table" | ||
set format "%.5f" | ||
set samples 500 | ||
set parametric | ||
|
||
|
||
# specific a parametric function | ||
set trange [0:2*pi] | ||
plot 7*sin(t), 4*cos(t) |
Oops, something went wrong.