
Preciso fazer um gráfico semelhante ao da foto. Tenho o início do código em LATEX, mas não funciona corretamente, você também precisa adicionar inscrições como na foto, você pode escrever no seu próprio idioma, eu posso editar. Eu realmente preciso de ajuda.
Meu código:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage[english, russian]{babel}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
ymin=0, ymax=14, % Устанавливаем минимальное и максимальное значение по оси Y
ymajorgrids=true, % Включаем сетку по оси Y
bar width=8pt, % Ширина столбцов
xlabel={Частота, Гц}, % Подпись оси X
ylabel={Среднеквадратическое значение напряжения, В}, % Подпись оси Y
xtick={220,225,...,320}, % Значения по оси X
xticklabels={220,225,...,320}, % Подписи значений по оси X
x tick label style={rotate=45,anchor=east}, % Стиль подписей по оси X
xticklabel style={
/pgf/number format/1000 sep=, % Убираем разделитель тысяч
rotate=90, % Поворачиваем подписи на 90 градусов
anchor=east % Якорь для поворота
},
enlarge x limits=0.05, % Увеличиваем пределы оси X для визуального комфорта
legend style={at={(0.5,-0.2)},anchor=north,legend columns=-1} % Расположение легенды
]
% Данные графика
\addplot coordinates {(220,0.5) (225,0.5) (230,0.5) (235,0.5) (240,0.5) (245,0.75) (250,14) (255,0.75) (260,1) (265,1.25) (270,1.5) (275,1.75) (280,2) (285,8) (290,6) (295,4) (300,3) (305,2) (310,1) (315,0.5) (320,0.5)};
% Добавляем пунктирные линии для подгрупп
\draw [dashed] (axis cs:240,0) -- (axis cs:240,14);
\draw [dashed] (axis cs:250,0) -- (axis cs:250,14);
\draw [dashed] (axis cs:290,0) -- (axis cs:290,14);
% Подписи для групп
\node at (axis cs:245,15) [anchor=north] {Гармоническая подгруппа};
\node at (axis cs:320,15) [anchor=north] {Интергармоническая группа};
\end{axis}
\end{tikzpicture}
\end{document}
Responder1
Aqui está uma maneira de fazer isso.
Marquei as alterações com % <<<
. Porém, a introdução das decorações dá um efeito estranho na caixa externa, que não consegui resolver. Um desvio pode ser, por exemplo, remover novamente as decorações e construir esses caminhos horizontais manualmente.
\documentclass[border=3mm]{standalone} % <<<
\usepackage{pgfplots}
\pgfplotsset{compat=1.17,width=20cm} % <<<
\usepackage[english, russian]{babel}
\usepackage[utf8]{inputenc}
\usetikzlibrary{decorations.pathreplacing} % <<<
\begin{document}
\begin{tikzpicture}[% some styles
txt/.style={fill=white,anchor=center},
decoration={brace,amplitude=3mm},
]
\begin{axis}[
ybar,
ymin=0, ymax=16, % <<< % Устанавливаем минимальное и максимальное значение по оси Y
ymajorgrids=true, % Включаем сетку по оси Y
bar width=8pt, % Ширина столбцов
xlabel={Частота, Гц}, % Подпись оси X
ylabel={Среднеквадратическое значение напряжения, В}, % Подпись оси Y
xtick={220,225,...,320}, % Значения по оси X
xticklabels={220,225,...,320}, % Подписи значений по оси X
x tick label style={
rotate=-90, % <<<
anchor=east}, % Стиль подписей по оси X
xticklabel style={
/pgf/number format/1000 sep=, % Убираем разделитель тысяч
rotate=90, % Поворачиваем подписи на 90 градусов
anchor=east % Якорь для поворота
},
enlarge x limits=0.05, % Увеличиваем пределы оси X для визуального комфорта
legend style={at={(0.5,-0.2)},anchor=north,legend columns=-1} % Расположение легенды
]
% Данные графика
\addplot coordinates {(220,0.5) (225,0.5) (230,0.5) (235,0.5) (240,0.5) (245,0.75) (250,14) (255,0.75) (260,1) (265,1.25) (270,1.5) (275,1.75) (280,2) (285,8) (290,6) (295,4) (300,3) (305,2) (310,1) (315,0.5) (320,0.5)};
% Добавляем пунктирные линии для подгрупп
% \draw [dashed] (axis cs:240,0) -- (axis cs:240,14);
% \draw [dashed] (axis cs:250,0) -- (axis cs:250,14);
% \draw [dashed] (axis cs:290,0) -- (axis cs:290,14);
\draw [dashed] (axis cs:237.3,0) -- (axis cs:237.5,14);
\draw [dashed] (axis cs:252.5,0) -- (axis cs:252.5,14);
\draw [dashed] (axis cs:247.5,0) -- (axis cs:247.5,12);
\draw [dashed] (axis cs:292.5,0) -- (axis cs:292.5,12);
% braces, as decorations
\draw[decorate,dashed] (axis cs:237.5,14) -- (axis cs:252.5,14);
\draw[decorate,dashed] (axis cs:247.5,12) -- (axis cs:292.5,12);
% Подписи для групп
\node at (axis cs:245,15) [txt] {Гармоническая подгруппа};
\node at (axis cs:270,13) [txt] {Интергармоническая группа};
\end{axis}
\end{tikzpicture}
\end{document}