Graphics, Figures & Tables ⇒ Tweaking some parts of a chart
Re: Tweaking some parts of a chart
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Tweaking some parts of a chart
\pgfplotsset{compat=newest}
.For further reference
Tweaking some parts of a chart
Code: Select all
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\pgfplots@drawaxis@lines@preparediscont@for}{ticks,segment length=4pt, amplitude=8pt}%
{ticks,segment length=4pt, amplitude=5pt,transform={rotate=45}}{}{}
\makeatother
\begin{document}
\begin{tikzpicture}
% f1
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=24,
%xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24},
xtick={0,4,8,12,24}, %%%<------------- here
xlabel=\ {Time},
ymin=0,
ymax=10,
ytick={0,1,2,3,4,5,6,7,8,9,10},% your code
yticklabels={0,1,2,3,4,5,6,7,8,9,10},% your code
ylabel=\ {log(Cfu/cm$^{2}$)},
y axis line style={black},
ytick style={black},
yticklabel style={black},
axis x line*=bottom,
axis y line*=left,
tick align = outside,]
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=square*,
mark options={solid,,rotate=180,fill=white}]
table[row sep=crcr]{
0 5\\
4 5\\
8 9.8\\
12 6.8\\
24 6.162\\};
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=square*,
mark options={solid,,rotate=180,fill=white}]
table[row sep=crcr]{
0 2\\
4 3\\
8 4.8\\
12 7.8\\
24 8.162\\};
\end{axis}
% f2
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=24,
ymin=0,
ymax=6,
ytick={0,1,2,3,4,5,6},
yticklabels={0,1,2,3,4,5,6},
axis x line*=none,
axis y line*=right,
ylabel=\ {RE},
ylabel style=black,
hide x axis,
tick align =outside,]
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark=*,
mark options={solid,fill=white}]
table[row sep=crcr]{
0 4.3\\
4 3.8\\
8 5.1\\
12 5.123\\
24 3.85\\};
\end{axis}
% f3
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=24,
ymin=0,
ymax=4000,
ytick={0,2000,4000},% your code
yticklabels={0,2000,4000},% your code
axis y discontinuity=parallel,% new
axis x line*=none,
axis y line*=right,
ylabel=\ {Enterotoxin production},
ylabel style=black,
hide x axis,
tick align =outside,]
\pgfplotsset{every outer y axis line/.style={xshift=1.5cm}, every tick/.style={xshift=1.5cm}, every y tick label/.style={xshift=1.5cm} }
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark=triangle*,
mark options={solid,,fill=white}]
table[row sep=crcr]{
0 2300\\
4 3800\\
8 3200\\
12 3123\\
24 2385\\};
\end{axis}
\end{tikzpicture}%
\end{document}
- Attachments
-
- OtKRX.jpg (10.7 KiB) Viewed 4086 times
- Stefan Kottwitz
- Site Admin
- Posts: 10328
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Tweaking some parts of a chart
Should not the scaling be different then, i.e. the third axis starts with 0, short discontinuity then it jumps to 1000 or so (that's why the gap!) and continues to 2000, 4000, ... The discontinuity should cover which range? From 0 to 0 or from 0 to 2000 - because it symbolizes a gap. Much words, I just want to understand and want to be clear.
What do you think? Is the current position undesirable? Is that discontinuity exactly at 0 definitely required?
Stefan
Re: Tweaking some parts of a chart
Best regards
- Stefan Kottwitz
- Site Admin
- Posts: 10328
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Tweaking some parts of a chart
Feel free to post a hand-drawing showing where a discontinuity, gap, jump, anything - until now it's a normal axis, continuous, where there should be a sign without reason, I think.
Stefan
Tweaking some parts of a chart
Also I want to ask how do 8 graph in one page:4 graph above, 4 graph below , but in one page.
I need my X axis show -168 hours, but when I write 0,4,8,12 hours very similar, how do all number far between.
Code: Select all
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\pgfplots@drawaxis@lines@preparediscont@for}{ticks,segment length=4pt, amplitude=8pt}%
{ticks,segment length=4pt, amplitude=5pt,transform={rotate=55}}{}{}
\makeatother
\begin{document}
\begin{tikzpicture}
% f1
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
%xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,48,72,168},
xtick={0,4,8,12,24,48,72,168}, %%%<------------- here
xlabel=\ {Time},
ymin=0,
ymax=10,
ytick={0,1,2,3,4,5,6,7,8,9,10},% your code
yticklabels={0,1,2,3,4,5,6,7,8,9,10},% your code
ylabel=\ {log(Cfu/cm$^{2}$)},
y axis line style={black},
ytick style={black},
yticklabel style={black},
axis x line*=bottom,
axis y line*=left,
tick align = outside,]
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=square*,
mark options={solid,,rotate=180,fill=white}]
table[row sep=crcr]{
0 5\\
4 5\\
8 9.8\\
12 6.8\\
24 6.162\\};
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=square*,
mark options={solid,,rotate=180,fill=white}]
table[row sep=crcr]{
0 2\\
4 3\\
8 4.8\\
12 7.8\\
24 8.162\\};
\end{axis}
% f2
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
ymin=0,
ymax=6,
ytick={0,1,2,3,4,5,6},
yticklabels={0,1,2,3,4,5,6},
axis x line*=none,
axis y line*=right,
ylabel=\ {RE},
ylabel style=black,
hide x axis,
tick align =outside,]
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark=*,
mark options={solid,fill=white}]
table[row sep=crcr]{
0 4.3\\
4 3.8\\
8 5.1\\
12 5.123\\
24 3.85\\};
\end{axis}
% f3
\begin{axis}[
color=red,
scale only axis,
xmin=0,
xmax=168,
ymin=0,
ymax=4000,
ytick={0,1000,2000,3000,4000},% your code
yticklabels={0,1000,2000,3000,4000},% your code
axis y discontinuity=parallel,% new
axis x line*=none,
axis y line*=right,
ylabel=\ {Enterotoxin production},
ylabel style=red,
hide x axis,
tick align =outside,]
\pgfplotsset{every outer y axis line/.style={xshift=1.5cm}, every tick/.style={xshift=1.5cm}, every y tick label/.style={xshift=1.5cm} }
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark=triangle*,
mark options={solid,,fill=white}]
table[row sep=crcr]{
0 2300\\
4 3800\\
8 3200\\
12 3123\\
24 2385\\};
\end{axis}
\end{tikzpicture}%
\end{document}
- Attachments
-
- DasagPlot.jpg (56.9 KiB) Viewed 4059 times
- Stefan Kottwitz
- Site Admin
- Posts: 10328
- Joined: Mon Mar 10, 2008 9:44 pm
Re: Tweaking some parts of a chart
Those 8 graphs could be arranged using the subfig package, minipages, par boxes, or tabular. I guess the last one would be a nice way. Or do you need captions? Numbering? Referencing)
regarding the x-axis issue you could perhaps hand-draw how the axis should finally look like, so we can understand and try.
Stefan
Tweaking some parts of a chart
Also You can wriyte code which in page 8 graphs for examle this graph-8x
Thank you
- Stefan Kottwitz
- Site Admin
- Posts: 10328
- Joined: Mon Mar 10, 2008 9:44 pm
Tweaking some parts of a chart
Here's a way.
- Load the
calc
library in the preamble afterpgfplots
:\usetikzlibrary{calc}
- Define a coordinate within the axis, so you can later refer to it:
\coordinate (pos) at (axis cs:198,2000);
- Draw after the axis has ended, before ending the TikZ picture:
Code: Select all
\newcommand*{\len}{0.2} \draw[double distance=2.2,double=white,draw=red,thick] ($(pos)-(\len,\len)$) -- ($(pos)+(\len,\len)$); \renewcommand*{\len}{0.21} \draw[double distance=2.2,double=white,draw=white,thin] ($(pos)-(\len,\len)$) -- ($(pos)+(\len,\len)$);
\len
for adjusting the length of the lines. Simply one double line would suffice, I just draw the second line for better cleaning between in white. Complete Code, my older code commented out:
Code: Select all
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{calc}
%\usepackage{etoolbox}
%\makeatletter
%\patchcmd{\pgfplots@drawaxis@lines@preparediscont@for}{ticks,segment length=4pt, amplitude=8pt}%
% {ticks,segment length=4pt, amplitude=5pt,transform={rotate=55}}{}{}
%\makeatother
\begin{document}
\begin{tikzpicture}
% f1
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
%xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,48,72,168},
xtick={0,4,8,12,24,48,72,168}, %%%<------------- here
xlabel=\ {Time},
ymin=0,
ymax=10,
ytick={0,1,2,3,4,5,6,7,8,9,10},% your code
yticklabels={0,1,2,3,4,5,6,7,8,9,10},% your code
ylabel=\ {log(Cfu/cm$^{2}$)},
y axis line style={black},
ytick style={black},
yticklabel style={black},
axis x line*=bottom,
axis y line*=left,
tick align = outside,]
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=square*,
mark options={solid,,rotate=180,fill=white}]
table[row sep=crcr]{
0 5\\
4 5\\
8 9.8\\
12 6.8\\
24 6.162\\};
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark size=2.5pt,
mark=square*,
mark options={solid,,rotate=180,fill=white}]
table[row sep=crcr]{
0 2\\
4 3\\
8 4.8\\
12 7.8\\
24 8.162\\};
\end{axis}
% f2
\begin{axis}[
color=black,
scale only axis,
xmin=0,
xmax=168,
ymin=0,
ymax=6,
ytick={0,1,2,3,4,5,6},
yticklabels={0,1,2,3,4,5,6},
axis x line*=none,
axis y line*=right,
ylabel=\ {RE},
ylabel style=black,
hide x axis,
tick align =outside,]
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark=*,
mark options={solid,fill=white}]
table[row sep=crcr]{
0 4.3\\
4 3.8\\
8 5.1\\
12 5.123\\
24 3.85\\};
\end{axis}
% f3
\begin{axis}[
color=red,
scale only axis,
xmin=0,
xmax=168,
ymin=0,
ymax=4000,
ytick={0,1000,2000,3000,4000},% your code
yticklabels={0,1000,2000,3000,4000},% your code
%axis y discontinuity=parallel,% new
axis x line*=none,
axis y line*=right,
ylabel=\ {Enterotoxin production},
ylabel style=red,
hide x axis,
tick align =outside,]
\pgfplotsset{every outer y axis line/.style={xshift=1.5cm}, every tick/.style={xshift=1.5cm}, every y tick label/.style={xshift=1.5cm} }
\addplot [
color=black,
solid,
line width=0.5pt,
mark size=2.5pt,
mark=triangle*,
mark options={solid,,fill=white}]
table[row sep=crcr]{
0 2300\\
4 3800\\
8 3200\\
12 3123\\
24 2385\\};
\coordinate (pos) at (axis cs:198,2000);
\end{axis}
\newcommand*{\len}{0.2}
\draw[double distance=2.2,double=white,draw=red,thick]
($(pos)-(\len,\len)$) -- ($(pos)+(\len,\len)$);
\renewcommand*{\len}{0.21}
\draw[double distance=2.2,double=white,draw=white,thin]
($(pos)-(\len,\len)$) -- ($(pos)+(\len,\len)$);
\end{tikzpicture}%
\end{document}

I may deal with it later, as I am busy right now. (If you keep posting the same at StackExchange, I may leave it to them and stop here).
Stefan