I have a basic figure where I want the following numbers to be in the Y axis 0.004,0.005,...,0.018
When I write them in the code they appear in a different way as you see in the screenshot. I know this is mathematically correct but they look odd and I want to them to be shown exactly as I put them in the code.
This is the code
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture} [style={outer sep=5}]
\begin{axis}[ymin=0.004,ymax=0.018, xmin=15, xmax=50,
xlabel= $Number of Nodes$, ylabel = $end-to-end (sec)$,
xtick={15,20,...,50},
ytick={0.004,0.005,...,0.018},
yticklabel style={/pgf/number format/fixed},
grid={major},clip=false,grid style={dashed},
title={},
legend style={at={(1.2 ,1)},anchor=north},
font=\footnotesize]
% TAODV
\addplot[color=blue, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates {
(15, 0.0072) +-(0.001, -0.001)
(20, 0.0079) +-(0.001, -0.001)
(25, 0.0092) +-(0.001, -0.001)
(30, 0.01) +-(0.001, -0.001)
(35, 0.013) +-(0.0018, -0.0018)
(40, 0.0137) +-(0.001, -0.001)
(45, 0.015) +-(0.001, -0.001)
(50, 0.0168)+-(0.001, -0.001)
};
% AODV
\addplot[color=red, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates {
(15, 0.0052) +-(0.001, -0.001)
(20, 0.0057) +-(0.001, -0.001)
(25, 0.0067) +-(0.001, -0.001)
(30, 0.0074) +-(0.001, -0.001)
(35, 0.0082) +-(0.0018, -0.0018)
(40, 0.0095) +-(0.001, -0.001)
(45, 0.01) +-(0.001, -0.001)
(50, 0.0109) +-(0.001, -0.001)
};
\legend{
$TAODV$,
$AODV$
}
\end{axis}
\end{tikzpicture}
\caption[End-to-end delay of TAODV vs. AODV]{End-to-end delay of TAODV vs. AODV with \%95 confidence interval}
\end{figure}
\end{document}
You can use scaled y ticks=false to switch off the common scaling factor. Please also note that math mode is a horrible choice for multi-letter words or even whole phrases.
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture} [style={outer sep=5}]
\begin{axis}[ymin=0.004,ymax=0.018, xmin=15, xmax=50,
xlabel= \emph{Number of Nodes}, ylabel = \emph{end-to-end (sec)},
xtick={15,20,...,50},
ytick={0.004,0.005,...,0.018},
grid={major},clip=false,grid style={dashed},
title={},
legend style={at={(1.2 ,1)},anchor=north},
font=\footnotesize,
scaled y ticks=false,
yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},
]
% TAODV
\addplot[color=blue, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates {
(15, 0.0072) +-(0.001, -0.001)
(20, 0.0079) +-(0.001, -0.001)
(25, 0.0092) +-(0.001, -0.001)
(30, 0.01) +-(0.001, -0.001)
(35, 0.013) +-(0.0018, -0.0018)
(40, 0.0137) +-(0.001, -0.001)
(45, 0.015) +-(0.001, -0.001)
(50, 0.0168)+-(0.001, -0.001)
};
% AODV
\addplot[color=red, mark=*, samples=10] [error bars/.cd,y dir=both, y explicit] coordinates {
(15, 0.0052) +-(0.001, -0.001)
(20, 0.0057) +-(0.001, -0.001)
(25, 0.0067) +-(0.001, -0.001)
(30, 0.0074) +-(0.001, -0.001)
(35, 0.0082) +-(0.0018, -0.0018)
(40, 0.0095) +-(0.001, -0.001)
(45, 0.01) +-(0.001, -0.001)
(50, 0.0109) +-(0.001, -0.001)
};
\legend{
\emph{TAODV},
\emph{AODV}
}
\end{axis}
\end{tikzpicture}
\caption[End-to-end delay of TAODV vs. AODV]{End-to-end delay of TAODV vs. AODV with \%95 confidence interval}
\end{figure}
\end{document}
Related
I have a tikzpicture where I use two def blocks to define two unique figures. I want to draw an arrow between two nodes and each of them locate in each def block. There are IDs assigned to each node, but the arrow I get is not what I want.
\usetikzlibrary{shapes}
\usetikzlibrary{math}
\def\clusterone{%
\begin{tikzpicture}[scale=1.0]
\foreach \radius [count=\angleCount from 0] in {0.2, 0.6, 0.4, 0.5}
{\node[draw=green, circle, inner sep=0pt, minimum size=2pt, fill=green] (c1-\angleCount) at ({\radius * cos(90 * \angleCount)}, {\radius * sin(90 * \angleCount)}) {};}
\end{tikzpicture}%
}
\def\clustertwo{%
\begin{tikzpicture}[scale=1.0]
\foreach \radius [count=\angleCount from 0] in {0.6, 0.1, 0.4, 0.6}
{\node[draw=green, circle, inner sep=0pt, minimum size=2pt, fill=green] (c2-\angleCount) at ({\radius * cos(90 * \angleCount)}, {\radius * sin(90 * \angleCount)}) {};}
\end{tikzpicture}%
}
\scalebox{1}{
\begin{tikzpicture}
\node[rotate=30] (node1) at (0, 1.5) {\clusterone};
\node[] at (0, 1.5) {1};
\node[rotate=30] (node2) at (0, 0) {\clustertwo};
\node[] at (0, 0) {2};
\draw[->] (c1-0) -- (c2-3);
\end{tikzpicture}
}
Expected
Current Result
Is there a way to address IDs of two nodes that are located inside two different tikzpictures? Or is there a way to draw an arrow between nodes in this situation?
Don't nest tikz pictures!
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{math}
\begin{document}
\def\clusterone{%
\foreach \radius [count=\angleCount from 0] in {0.2, 0.6, 0.4, 0.5}
{\node[draw=green, circle, inner sep=0pt, minimum size=2pt, fill=green] (c1-\angleCount) at ({\radius * cos(90 * \angleCount)}, {\radius * sin(90 * \angleCount)}) {};}
}
\def\clustertwo{%
\foreach \radius [count=\angleCount from 0] in {0.6, 0.1, 0.4, 0.6}
{\node[draw=green, circle, inner sep=0pt, minimum size=2pt, fill=green] (c2-\angleCount) at ({\radius * cos(90 * \angleCount)}, {\radius * sin(90 * \angleCount)}) {};}
}
\begin{tikzpicture}
\begin{scope}[yshift=1.5cm]
\clusterone
\end{scope}
\node[] at (0, 1.5) {1};
\begin{scope}
\clustertwo
\end{scope}
\node[] at (0, 0) {2};
\draw[->] (c1-0) -- (c2-3);
\end{tikzpicture}
\end{document}
I'd like to draw a line plot the years on the x-axis with xmax = 2020 in LateX pgfplots. As my data ends in 2019 I get a vertical line at 2019. It's probably quite easy but I didn't find anything about how to avoid that.
Thanks in advance!
Example code:
\documentclass[tikz, border=1mm]{standalone}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
width = 0.6\textwidth,
xticklabel style=
{/pgf/number format/1000 sep=,rotate=90,anchor=east},
xmin = 1995, xmax = 2020,
ymin = 0, ymax = 1.2,
xlabel = Year,
ylabel style ={align=center}, ylabel = Specific energy consumption\\in kWh/pkm,
yticklabels={, 0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2}]
\addplot [] coordinates {
(1995,1.102) (1996,1.067) (1997,1.048) (1998,0.939) (1999,0.905) (2000,0.901) (2001,0.924) (2002,0.944) (2003,0.906) (2004,0.9) (2005,0.901) (2006,0.89) (2007,0.854) (2008,0.829) (2009,0.813) (2010,0.839) (2011,0.846) (2012,0.831) (2013,0.772) (2014,0.768) (2015,0.785) (2016,0.794) (2017,0.765) (2018,0.755) (2019,0.768) } \closedcycle;
\end{axis}
\end{tikzpicture}
\end{figure}
With \closedcycle you explicitly add the line
\documentclass[tikz, border=1mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[
width = 0.6\textwidth,
xticklabel style=
{/pgf/number format/1000 sep=,rotate=90,anchor=east},
xmin = 1995, xmax = 2020,
ymin = 0, ymax = 1.2,
xlabel = Year,
ylabel style ={align=center}, ylabel = Specific energy consumption\\in kWh/pkm,
yticklabels={, 0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2}]
\addplot [] coordinates {
(1995,1.102) (1996,1.067) (1997,1.048) (1998,0.939) (1999,0.905) (2000,0.901) (2001,0.924) (2002,0.944) (2003,0.906) (2004,0.9) (2005,0.901) (2006,0.89) (2007,0.854) (2008,0.829) (2009,0.813) (2010,0.839) (2011,0.846) (2012,0.831) (2013,0.772) (2014,0.768) (2015,0.785) (2016,0.794) (2017,0.765) (2018,0.755) (2019,0.768) }
% \closedcycle
;
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
I have this image and I would like to find where the crossties are (either bounding boxes or masks works). Crossties are the horizontal blocks between the two rails. Just the rails in the middle are sufficient.
I have been struggling for quite a while now. I found the function cv2.HoughLinesP but I could not make it work.
Has anyone ever done something similar or know how to do it?
It would be very helpful.
# 213, 205, 210
# 207, 200, 204
# 201, 195, 199
# 215, 208, 206
# 200, 195, 192
import cv2
import numpy as np
img = cv2.cvtColor(cv2.imread('out2168.png'), cv2.COLOR_BGR2RGB)
img = img[:, 300:400]
canny = cv2.Canny(img, 30, 120)
lines = cv2.HoughLines(canny, 1, np.pi / 360, 20)
for rho, theta in lines[0]:
a = np.cos(theta)
b = np.sin(theta)
x0 = a * rho
y0 = b * rho
x1 = int(x0 + 1000 * (-b))
y1 = int(y0 + 1000 * a)
x2 = int(x0 - 1000 * (-b))
y2 = int(y0 - 1000 * a)
cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 2)
cv2.imshow('rail', img)
cv2.waitKey(0)
References:
OpenCV houghLinesP parameters
https://docs.opencv.org/3.4/d9/db0/tutorial_hough_lines.html
I am currently working on a code on how to paint on facial landmarks in real-time using opencv and face_recognition module. I saw a source code on the internet about painting over an image using PIL and face_recognition, I was wondering what module is the counterpart of PIL in terms of manipulating videos? I want to find the landmarks of the face that is showing on the webcam and paint on those landmarks (example: eyebrows, lips etc)
This is my current code:
from PIL import Image, ImageDraw
import face_recognition
import cv2
video_capture = cv2.VideoCapture(0)
face_locations = []
process_this_frame = True
face_landmarks_list = []
while True:
ret, frame = video_capture.read()
small_frame = cv2.resize(frame, (0, 0), fx = 0.25, fy = 0.25)
rgb_small_frame = small_frame[:, :, ::-1]
if process_this_frame:
face_locations = face_recognition.face_locations(rgb_small_frame)
face_landmarks_list = face_recognition.face_landmarks(rgb_small_frame)
for face_landmarks in face_landmarks_list:
pil_image = Image.fromarray(rgb_small_frame)
d = ImageDraw.Draw(pil_image, 'RGBA')
# Make the eyebrows into a nightmare
d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))
d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128))
d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5)
d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5)
# Gloss the lips
d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128))
d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))
d.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=8)
d.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=8)
# Sparkle the eyes
d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))
d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30))
# Apply some eyeliner
d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=6)
d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=6)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
I'm following this tutorial about opencv and camera calibration.
When I'm executing the below code I get the error message:
MacBook-Pro:src marvineffing$ python3 pose\ estimation.py
OpenCV Error: Assertion failed (d == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0)) in create, file /tmp/opencv320151207-39796-10do3cp/opencv-3.0.0/modules/core/src/matrix.cpp, line 2294
Traceback (most recent call last):
File "pose estimation.py", line 31, in <module>
rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)
cv2.error: /tmp/opencv320151207-39796-10do3cp/opencv-3.0.0/modules/core/src/matrix.cpp:2294: error: (-215) d == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0) in function create
Code:
import cv2
import numpy as np
import glob
def draw(img, corners, imgpts):
"""draws line on xyz axis for a corner"""
corner = tuple(corners[0].ravel())
img = cv2.line(img, corner, tuple(imgpts[0].ravel(), (255, 0, 0)))
img = cv2.line(img, corner, tuple(imgpts[1].ravel(), (0, 255, 0)))
img = cv2.line(img, corner, tuple(imgpts[2].ravel(), (0, 0, 255)))
return img
with np.load('matrix.npz') as X:
mtx, dist, _, _ = [X[i] for i in ('mtx', 'dist', 'rvecs', 'tvecs')]
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
objp = np.zeros((6*7, 3), np.float32)
objp[:, :2] = np.mgrid[0:7, 0:6].T.reshape(-1, 2)
axis = np.float32([[3, 0, 0], [0, 3, 0], [0, 0, -3]]).reshape(-1, 3)
for fname in glob.glob('../sample_images/left*.jpg'):
img = cv2.imread(fname)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret, corners = cv2.findChessboardCorners(gray, (7, 6),None)
if ret == True:
corners2 = cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
# Find the rotation and translation vectors.
rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)
# project 3D points to image plane
imgpts, jac = cv2.projectPoints(axis, rvecs, tvecs, mtx, dist)
img = draw(img, corners2,imgpts)
cv2.imshow('img', img)
k = cv2.waitKey(0) & 0xff
if k == 's':
cv2.imwrite(fname[:6]+'.png', img)
cv2.destroyAllWindows()
I tried the solutions offered after searching the internet, but this did not help me. Any help is welcome. I checked every argument, and they appear to be correct, but I'm very new to both python and opencv.
change
objp = np.zeros((6*7, 3), np.float32)
objp[:, :2] = np.mgrid[0:7, 0:6].T.reshape(-1, 2)
to
objp = np.zeros((6*7, 1, 3), np.float32)
objp[:,:,:2] = np.mgrid[0:7, 0:6].T.reshape(-1,1,2)
change
rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)
to
_, rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)