%!TEX TS-program = xelatex
\documentclass[12pt, a4paper]{article}  

\usepackage{amsmath,amsfonts,amssymb,amsthm,mathtools}  % пакеты для математики


%%%%%%%%%%%%%%%%%%%%%%%% Шрифты %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[british,russian]{babel} % выбор языка для документа
\usepackage[utf8]{inputenc} % задание utf8 кодировки исходного tex файла

\usepackage{fontspec}         % пакет для подгрузки шрифтов
\setmainfont{Arial}   % задаёт основной шрифт документа

\usepackage{unicode-math}     % пакет для установки математического шрифта
%\setmathfont{Asana Math}      % шрифт для математики

%%%%%%%%%% Работа с картинками %%%%%%%%%
\usepackage{graphicx}                  % Для вставки рисунков
\usepackage{graphics} 
\graphicspath{{images/}{pictures/}}    % можно указать папки с картинками
\usepackage{wrapfig}                   % Обтекание рисунков и таблиц текстом


%%%%%%%%%% Работа с таблицами %%%%%%%%%%
\usepackage{tabularx}            % новые типы колонок
\usepackage{tabulary}            % и ещё новые типы колонок
\usepackage{array}               % Дополнительная работа с таблицами
\usepackage{longtable}           % Длинные таблицы
\usepackage{multirow}            % Слияние строк в таблице
\usepackage{float}               % возможность позиционировать объекты в нужном месте 
\usepackage{booktabs}            % таблицы как в книгах!  
\renewcommand{\arraystretch}{1.3} % больше расстояние между строками

% Заповеди из документации к booktabs:
% 1. Будь проще! Глазам должно быть комфортно
% 2. Не используйте вертикальные линни
% 3. Не используйте двойные линии. Как правило, достаточно трёх горизонтальных линий
% 4. Единицы измерения - в шапку таблицы
% 5. Не сокращайте .1 вместо 0.1
% 6. Повторяющееся значение повторяйте, а не говорите "то же"
% 7. Есть сомнения? Выравнивай по левому краю!

%%%%%%%%%%%%%%%%%%%%%%%% Оформление %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[paper=a4paper,top=15mm, bottom=15mm,left=35mm,right=10mm,includefoot]{geometry}

\usepackage{indentfirst}       % установка отступа в первом абзаце главы


%%%%%%%%%%%%%%%%%%%%%%%% Графики и рисование %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz, pgfplots}  % язык для рисования графики из latex'a

% Всякие странные команды из Geogebra и с сайта для TikZ
\usepackage{pgf}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}

\definecolor{ffzzzz}{rgb}{1.,0.6,0.6}
\definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1.}
\definecolor{qqqqff}{rgb}{0.,0.,1.}
\definecolor{cqcqcq}{rgb}{0.7529411764705882,0.7529411764705882,0.7529411764705882}

\usetikzlibrary{calc}
\usepackage{relsize}
\newcommand\LM{\ensuremath{\mathit{LM}}}
\newcommand\IS{\ensuremath{\mathit{IS}}}

\usepackage{pgf,tikz}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}

\definecolor{ududff}{rgb}{0.30196078431372547,0.30196078431372547,1.}
\definecolor{cqcqcq}{rgb}{0.7529411764705882,0.7529411764705882,0.7529411764705882}

\title{Графика в LaTeX, TikZ}
\date{\today}


\begin{document} % конец преамбулы, начало документа

\section{Великий и могучий Tikz}
\subsection{ Основные команды} 

% Никогда не забывать в конце каждой строки ставить ;
% Tikz очень капризен по отношению к этому!

\begin{center}
\begin{tikzpicture}
\draw[red, dashed, thick] (0,1) -- (2,1) (0,2) -- (2,2);
\draw[->] (0,1) -- (-1,1);
\draw[blue,fill=yellow](2,2) circle [radius = 0.5];
\end{tikzpicture}
\end{center}

\vspace{1cm}

\begin{tikzpicture}
\foreach \x in {0,...,9}
  \draw [->] (\x,0)--(\x,-1);
\end{tikzpicture}

\vspace{1cm}

%\draw [domain=<xmin>:<xmax>] plot (\x, {function})

\begin{tikzpicture}
\draw [help lines] (-2,0) grid (2,4); 
\draw [->] (-2.2,0) -- (2.2,0); 
\draw [->] (0,0) -- (0,4.2); 
\draw [green, thick, domain=-2:2] plot (\x, {4-(\x)^2}); 
\draw [domain=-2:2, samples=500] plot (\x, {1+cos(pi*\x r});
\end{tikzpicture}


\begin{tikzpicture}[scale=2]
\draw[fill] (0.5,0.75) circle [radius=0.025];
\node [below right, red] at (0.5,0.75) {below right};
\node [above left, green] at (0.5,0.75) {above left};
\node [below left, purple] at (0.5,0.75) {below left};
\node [above right, magenta] at (0.5,0.75) {above right};
\end{tikzpicture}
% измнение scale не изменяет размер текста

\newpage

\subsection{Пример рисунка} 

\begin{figure}[H]
	\begin{minipage}[H]{0.39\linewidth}
		\begin{center}
			\[ f(p) = \begin{cases}
			2p&, p \in [0;1] \\
			0&, \text{иначе.}\\
			\end{cases} \]
		\end{center}
	\end{minipage}
	\hfill
	\begin{minipage}[H]{0.59\linewidth}
		\begin{center}
			\begin{tikzpicture}[scale=0.8]
			% оси
			\draw [->] (-3.8,0) -- (4,0);
			\draw [->] (0,0) -- (0,4.5);
			% график
			\draw [blue, thick, domain=0:2] plot (\x,2*\x);
			\draw [->, blue, thick] (-3.8,0)--(-0.05,0);
			\draw [<-, blue, thick] (2.05,0)--(4,0);
			\draw [blue, thick,dashed] (2,0)--(2,4);
			\draw [blue, thick,dashed] (0,4)--(2,4);
			% точки
			\draw[fill,blue] (2,4) circle [radius=0.03];
			\draw[fill,blue] (0,4) circle [radius=0.03];
			% подписи
			\node [below] at (0,0) {0};
			\node [below] at (2,0) {1};
			\node [left] at (0,4) {2};
			\node [below right] at (4,0) {$p$};
			\node [above left] at (0,4.3) {$f(p)$};
			\end{tikzpicture}
		\end{center}
	\end{minipage}
\end{figure}

\subsection{Ещё пример рисунка} 

\begin{figure}[H]
	\begin{minipage}[H]{0.49\linewidth}
		\center Априорное распределение: \\[2.5ex]
		\begin{tikzpicture}
		% оси
		\draw [->] (-3.8,0) -- (4,0);
		\draw [->] (0,0) -- (0,3.5);
		% график
		\draw [blue, thick, domain=0:2] plot (\x, 2);
		\draw [->, blue, thick] (-3.8,0)--(-0.05,0);
		\draw [<-, blue, thick] (2.05,0)--(4,0);
		\draw [blue, thick,dashed] (2,0)--(2,2);
		% точки
		\draw[fill,blue] (2,2) circle [radius=0.03];f
		\draw[fill,blue] (0,2) circle [radius=0.03];
		% подписи
		\node [below] at (0,0) {0};
		\node [below] at (2,0) {1};
		\node [left] at (0,2) {1};
		\node [below right] at (4,0) {$p$};
		\node [left] at (0,3.3) {$f(p)$};
		\end{tikzpicture}
	\end{minipage}
	\hfill
	\begin{minipage}[H]{0.49\linewidth}
		\center Апостериорное распределение: \\[2.5ex]
		\begin{tikzpicture}
		% оси
		\draw [->] (-3.8,0) -- (3,0);
		\draw [->] (0,0) -- (0,3.5);
		% график12
		\draw [blue, thick, domain=0:1] plot (\x, {12*\x*\x*(1-\x)});
		\draw [blue, thick] (-3.8,0)--(0,0);
		\draw [blue, thick] (1,0)--(3,0);
		% подписи
		\node [below] at (0,0) {0};
		\node [below] at (1,0) {1};
		\node [below right] at (3,0) {$p$};
		\node [left] at (0,3.3) {$f(p)$};
		\end{tikzpicture}
	\end{minipage}
\end{figure}


\newpage


\subsection{Tikztempaltes и их редактирование}

% Пример взят отсюда!
% http://www.texample.net/tikz/examples/is-lm-diagram/

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}[
        scale=2,
        IS/.style={blue, thick},
        LM/.style={red, thick},
        axis/.style={very thick, ->, >=stealth', line join=miter},
        important line/.style={thick}, dashed line/.style={dashed, thin},
        every node/.style={color=black},
        dot/.style={circle,fill=black,minimum size=4pt,inner sep=0pt,
            outer sep=-1pt},
    ]
    % axis
    \draw[axis,<->] (2.5,0) node(xline)[right] {$Y$} -|
                    (0,2.5) node(yline)[above] {$i$};
    % IS-LM diagram
    \draw[LM] (0.2,0.3) coordinate (LM_1) parabola (1.8,1.8)
        coordinate (LM_2) node[above] {\LM};
    \draw[IS] (0.2,1.8) coordinate (IS_1) parabola[bend at end]
         (1.8,.3) coordinate (IS_2) node[right] {\IS};
    %Intersection is calculated "manually" since Tikz does not offer
    %intersection calculation for parabolas
    \node[dot,label=above:$A$] at (1,.68) (int1) {};
    %shifted IS-LM diagram
    \draw[xshift=.7cm, LM, red!52] (0.2,0.2) parabola (1.8,1.7)
        node[above] {\LM'};
    \draw[xshift=.4cm, yshift=.3cm, IS, blue!60] (0.2,1.8)
        parabola[bend at end] (1.8,.3)
        node[right] {\IS'};
    %Intersection of shifted IS-LM
    \path[xshift=.36cm, yshift=.35cm] (.98,.7)
        node[dot,label=above:{$B$}] (int2) {};
    \path[xshift=.805cm] (1,.68) node[dot,label=above:$C$] (int3) {};
    %arrows between intersections
    \draw[->, very thick, black, >=stealth']
        ($(int1)+1/2*(-.80,1)$) -- ($(int2)+1/2*(-.8,1)$)
        node[sloped, above, midway] {$\mathsmaller{\Delta G > 0}$};
    \draw[->, very thick, black, >=stealth']
        ($(int2)+2*(.14,.2)$) -- ($(int2)!.2cm!270:(int2)+(.9,0)$)
        node[sloped,above, midway] {$\mathsmaller{\Delta M>0}$};
        
    \begin{scope}[xshift=4cm]
        %E-diagram
        \draw[axis,<->] (0,2.5) node(eyline)[above] {$i$} |-
                        (2.5,0) node(exline)[right] {$E$};

        \draw[important line, green, xshift=.5cm]
            (.2,.2) coordinate (es) -- (1.5,1.5) coordinate (ee)
            node [above right] {Interest rate parity};
    \end{scope}
    %Lines connecting IS LM coordinates and E coordinates
    \draw[dashed] 
        let
            % Store the intersection point in \p1 for later retrieval. 
            % A convenient feature of the let operation is that we can
            % access the x and y component of the coordinate directly 
            % using the \x1 and \y1 syntax. 
            \p1=(intersection of int2--[xshift=1]int2 and es--ee)
        in
            (0,\y1) node[left]{$i'$} -|  (\x1,0)
            node[pos=0.5,dot,label=above:$B'$] {} node[below] {$E'$};

    \draw[dashed line] let
        \p1=(intersection of int3--[xshift=1]int3 and es--ee)
            in
        (0,\y1) node[left]{$i\phantom{'}$} -| (\x1,0)
        node[dot,label=above:$C'$,pos=0.5] {} node[below] {$E$};

\end{tikzpicture}
\end{center}
\caption{Модель IS-LM }
\end{figure}

\newpage 

\subsection{Geogebra}

% Магия geogebra! 


	\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
	\draw[->,color=black] (-4.3,0.) -- (11.02,0.);
	\foreach \x in {-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.}
	\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
	\draw[->,color=black] (0.,-5.98) -- (0.,6.3);
	\foreach \y in {-5.,-4.,-3.,-2.,-1.,1.,2.,3.,4.,5.,6.}
	\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
	\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
	\clip(-4.3,-5.98) rectangle (11.02,6.3);
	\draw [line width=2.pt] (4.04,2.42) circle (2.2542404485768595cm);
	\draw [line width=2.pt] (-0.24,3.1)-- (7.6,0.6);
	\begin{scriptsize}
	\draw [fill=ududff] (4.04,2.42) circle (2.5pt);
	\draw[color=ududff] (4.18,2.79) node {$A$};
	\draw [fill=ududff] (2.04,1.38) circle (2.5pt);
	\draw[color=ududff] (2.18,1.75) node {$B$};
	\draw[color=black] (2.96,4.11) node {$c$};
	\draw [fill=ududff] (-0.24,3.1) circle (2.5pt);
	\draw[color=ududff] (-0.1,3.47) node {$C$};
	\draw [fill=ududff] (7.6,0.6) circle (2.5pt);
	\draw[color=ududff] (7.74,0.97) node {$D$};
	\draw[color=black] (3.64,1.73) node {$f$};
	\end{scriptsize}
	\end{tikzpicture}


\end{document} % конец документа