I am trying to create tikzpicture with vertical aligned numbers on the right side. But as you can see for example the numbers 10 and 11 are not aligned because the 0 is "bigger" than zero. How is it possible to align the numbers? Is it maybe better to use a table? If yes, how can I align the lines perfectly with the stacked bar?
\documentclass[tikz, class=scrreprt, fontsize=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[lf, p, sflf, sfp]{libertine}
\usepackage[libertine]{newtxmath}
\usepackage[stretch=10, shrink=10, final]{microtype}
\usepackage[detect-family]{siunitx}
\usepackage{pgfplots}
\usetikzlibrary{shapes, arrows.meta, positioning, calc, decorations.pathreplacing, calligraphy, intersections, backgrounds}
\tikzset{every picture/.style={/utils/exec={\sffamily\normalsize}}}
\definecolor{black}{RGB}{0,0,0} % schwarz
\definecolor{dark}{RGB}{215,48,31} % dunkelrot
\definecolor{orange}{RGB}{252,141,89} % orange
\definecolor{yellow}{RGB}{253,204,138} % gelb
\definecolor{light}{RGB}{254,240,217} % hellgelb
\definecolor{white}{RGB}{255,255,255} % weiß
\tikzstyle{invisbox} = [rectangle, minimum width = 7cm, draw = black, outer sep = 0, inner sep = 0, text width = 7cm, align = left]
\tikzstyle{numbox} = [rectangle, minimum width = 2cm, draw = black, outer sep = 0, inner sep = 0, text width = 2cm, align = right]
\tikzstyle{line} = [solid, line cap = round, line width = 0.05em]
\begin{document}
\begin{tikzpicture}
\pgfplotsset{every axis/.append style={
compat = 1.18,
width = 12cm,
height = 10cm,
ymajorgrids,
axis y line = left,
axis x line* = bottom,
x axis line style = {line width = 1pt, line cap = round, shorten >= -0.75cm},
y axis line style = {line width = 1pt, line cap = round, -{Triangle[width = 6pt, length = 6pt, round, line width = 1pt]}, shorten >= -0.75cm},
grid style = {line width = 0.2pt, draw = light, opacity = 0.5, line cap = round},
legend style = {draw = black, line width = 0.5pt, legend cell align = left, at = {(0.96, 1.02)}, anchor = north east},
xticklabel = {$\mathsf{\pgfmathprintnumber{\tick}}$},
yticklabel = {$\mathsf{\pgfmathprintnumber{\tick}}$},
tick style = {line cap = round, draw = black},
tick align = inside,
x tick label style = {
align = center,
/pgf/number format/.cd,
fixed,
precision = 2,
use comma,
1000 sep = {},
},
y tick label style = {
align = right,
/pgf/number format/.cd,
fixed,
precision = 2,
use comma,
1000 sep = {},
},
/pgfplots/layers/PhDStyle/.define layer set = {
axis background, axis grid, axis ticks, main, axis lines, axis tick labels,
axis descriptions, axis foreground
}{/pgfplots/layers/standard},
set layers = PhDStyle
}}
\begin{axis}[%
ymin = 0, ymax = 100,
ytick = {0, 20, 40, 60, 80, 100},
symbolic x coords = {2020, 2025, 2030},
xlabel = {Jahr},
ylabel = {Marktvolumen (in Milliarden USD)},
enlarge x limits = {abs = 2cm},
xtick = data,
bar width = 2cm,
rounded corners = 1pt
]
\addplot[ybar, fill = none, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 34
2025, 63
2030, 84
};
\addplot[ybar stacked, fill = dark, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 15
2025, 32
2030, 43
};
\addplot[ybar stacked, fill = orange, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 8
2025, 15
2030, 18
};
\addplot[ybar stacked, fill = yellow, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 5
2025, 5
2030, 6
};
\addplot[ybar stacked, fill = light, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 4
2025, 6
2030, 9
};
\addplot[ybar stacked, fill = white, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 3
2025, 5
2030, 8
};
\end{axis}
\draw [line, line width = 1pt] (10cm, 7.071cm) -- (19cm, 7.071cm);
\draw [line] (10cm, 6.398cm) -- (19cm, 6.398cm);
\draw [line] (10cm, 5.64cm) -- (19cm, 5.64cm);
\draw [line] (10cm, 5.135cm) -- (19cm, 5.135cm);
\draw [line] (10cm, 3.62cm) -- (19cm, 3.62cm);
\draw [line, line width = 1pt] (10cm, 0cm) -- (19cm, 0cm);
\node [invisbox, minimum height = 0.673cm] at (13.5cm, 6.7345cm) (text1) {OS and Middleware};
\node [invisbox, minimum height = 0.758cm] at (13.5cm, 6.019cm) (text2) {\raisebox{-9pt}{Body and Energy}};
\node [invisbox, minimum height = 0.505cm] at (13.5cm, 5.3875cm) (text3) {Powertrain and Chassis};
\node [invisbox, minimum height = 1.515cm] at (13.5cm, 4.3755cm) (text4) {\raisebox{-9pt}{Infotainment, Connectivity, Security}};
\node [invisbox, minimum height = 3.62cm] at (13.5cm, 1.81cm) (text5) {\raisebox{-9pt}{Fahrerassistenzsysteme und autonomes Fahren}};
\node [invisbox, above = 0cm of text1, minimum height = 0.5cm] (text0) {\textbf{Total}};
\node [numbox, right = 0cm of text0, minimum height = 0.5cm] {\textbf{\SI{9}{\percent}}};
\node [numbox, right = 0cm of text1, minimum height = 0.673cm] {\SI{11}{\percent}};
\node [numbox, right = 0cm of text2, minimum height = 0.758cm] {\SI{10}{\percent}};
\node [numbox, right = 0cm of text3, minimum height = 0.505cm] {\SI{1}{\percent}};
\node [numbox, right = 0cm of text4, minimum height = 1.515cm] {\SI{9}{\percent}};
\node [numbox, right = 0cm of text5, minimum height = 3.62cm] {\SI{11}{\percent}};
\end{tikzpicture}
\end{document}
You can make sure all your figures have the same width by loading the libertine package with the t option for "tabular figures"
\documentclass[tikz, class=scrreprt, fontsize=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[t]{libertine}
\usepackage[libertine]{newtxmath}
\usepackage[stretch=10, shrink=10, final]{microtype}
\usepackage[detect-family]{siunitx}
\usepackage{pgfplots}
\usetikzlibrary{shapes, arrows.meta, positioning, calc, decorations.pathreplacing, calligraphy, intersections, backgrounds}
\tikzset{every picture/.style={/utils/exec={\sffamily\normalsize}}}
\definecolor{black}{RGB}{0,0,0} % schwarz
\definecolor{dark}{RGB}{215,48,31} % dunkelrot
\definecolor{orange}{RGB}{252,141,89} % orange
\definecolor{yellow}{RGB}{253,204,138} % gelb
\definecolor{light}{RGB}{254,240,217} % hellgelb
\definecolor{white}{RGB}{255,255,255} % weiß
\tikzstyle{invisbox} = [rectangle, minimum width = 7cm, draw = black, outer sep = 0, inner sep = 0, text width = 7cm, align = left]
\tikzstyle{numbox} = [rectangle, minimum width = 2cm, draw = black, outer sep = 0, inner sep = 0, text width = 2cm, align = right]
\tikzstyle{line} = [solid, line cap = round, line width = 0.05em]
\begin{document}
\begin{tikzpicture}
\pgfplotsset{every axis/.append style={
compat = 1.18,
width = 12cm,
height = 10cm,
ymajorgrids,
axis y line = left,
axis x line* = bottom,
x axis line style = {line width = 1pt, line cap = round, shorten >= -0.75cm},
y axis line style = {line width = 1pt, line cap = round, -{Triangle[width = 6pt, length = 6pt, round, line width = 1pt]}, shorten >= -0.75cm},
grid style = {line width = 0.2pt, draw = light, opacity = 0.5, line cap = round},
legend style = {draw = black, line width = 0.5pt, legend cell align = left, at = {(0.96, 1.02)}, anchor = north east},
xticklabel = {$\mathsf{\pgfmathprintnumber{\tick}}$},
yticklabel = {$\mathsf{\pgfmathprintnumber{\tick}}$},
tick style = {line cap = round, draw = black},
tick align = inside,
x tick label style = {
align = center,
/pgf/number format/.cd,
fixed,
precision = 2,
use comma,
1000 sep = {},
},
y tick label style = {
align = right,
/pgf/number format/.cd,
fixed,
precision = 2,
use comma,
1000 sep = {},
},
/pgfplots/layers/PhDStyle/.define layer set = {
axis background, axis grid, axis ticks, main, axis lines, axis tick labels,
axis descriptions, axis foreground
}{/pgfplots/layers/standard},
set layers = PhDStyle
}}
\begin{axis}[%
ymin = 0, ymax = 100,
ytick = {0, 20, 40, 60, 80, 100},
symbolic x coords = {2020, 2025, 2030},
xlabel = {Jahr},
ylabel = {Marktvolumen (in Milliarden USD)},
enlarge x limits = {abs = 2cm},
xtick = data,
bar width = 2cm,
rounded corners = 1pt
]
\addplot[ybar, fill = none, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 34
2025, 63
2030, 84
};
\addplot[ybar stacked, fill = dark, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 15
2025, 32
2030, 43
};
\addplot[ybar stacked, fill = orange, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 8
2025, 15
2030, 18
};
\addplot[ybar stacked, fill = yellow, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 5
2025, 5
2030, 6
};
\addplot[ybar stacked, fill = light, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 4
2025, 6
2030, 9
};
\addplot[ybar stacked, fill = white, draw = black, area legend, line width = 0.5pt] table[col sep = comma] {%
x y
2020, 3
2025, 5
2030, 8
};
\end{axis}
\draw [line, line width = 1pt] (10cm, 7.071cm) -- (19cm, 7.071cm);
\draw [line] (10cm, 6.398cm) -- (19cm, 6.398cm);
\draw [line] (10cm, 5.64cm) -- (19cm, 5.64cm);
\draw [line] (10cm, 5.135cm) -- (19cm, 5.135cm);
\draw [line] (10cm, 3.62cm) -- (19cm, 3.62cm);
\draw [line, line width = 1pt] (10cm, 0cm) -- (19cm, 0cm);
\node [invisbox, minimum height = 0.673cm] at (13.5cm, 6.7345cm) (text1) {OS and Middleware};
\node [invisbox, minimum height = 0.758cm] at (13.5cm, 6.019cm) (text2) {\raisebox{-9pt}{Body and Energy}};
\node [invisbox, minimum height = 0.505cm] at (13.5cm, 5.3875cm) (text3) {Powertrain and Chassis};
\node [invisbox, minimum height = 1.515cm] at (13.5cm, 4.3755cm) (text4) {\raisebox{-9pt}{Infotainment, Connectivity, Security}};
\node [invisbox, minimum height = 3.62cm] at (13.5cm, 1.81cm) (text5) {\raisebox{-9pt}{Fahrerassistenzsysteme und autonomes Fahren}};
\node [invisbox, above = 0cm of text1, minimum height = 0.5cm] (text0) {\textbf{Total}};
\node [numbox, right = 0cm of text0, minimum height = 0.5cm] {\textbf{\SI{9}{\percent}}};
\node [numbox, right = 0cm of text1, minimum height = 0.673cm] {\SI{11}{\percent}};
\node [numbox, right = 0cm of text2, minimum height = 0.758cm] {\SI{10}{\percent}};
\node [numbox, right = 0cm of text3, minimum height = 0.505cm] {\SI{1}{\percent}};
\node [numbox, right = 0cm of text4, minimum height = 1.515cm] {\SI{9}{\percent}};
\node [numbox, right = 0cm of text5, minimum height = 3.62cm] {\SI{11}{\percent}};
\end{tikzpicture}
\end{document}
Related
Tikz capabilities to draw lines from node to node a very useful, e.g, for something like:
However, if the node should have size 0 (i.e., no description) the outgoing or incoming line stops before the actual point. This is for instance the case if it is only used to mark a point in the coordinate system, See, e.g., node (1,1) or (0,0) in the following picture:
The code for the second picture writes:
\node at(0,0) (origin) {};
\node[below = 0.0cm of origin]{$(0,0)$};
\node[above = 3cm of origin] (y) {$y$};
\node[right = 3cm of origin] (z) {$z$};
\node[above = 2cm of origin, left] (y1) {$1$};
\node[right = 2cm of origin, below] (z1) {$1$};
\node[right = 2cm of y1] (yz1) {};
\node[above = 2.5cm of z] (endgz) {};
\node[above = 3cm of z] (yz) {};
\node[above = 1cm of origin] (p0) {};
\draw[fill](p0) circle(0.06cm);
\node[left=0cm of p0]{$g(0)=p0$};
\draw[fill](yz1) circle(0.06cm);
\draw[->,thick] (0,0) -- (y);
\draw[->,thick] (0,0) -- (z);
\draw (origin) -- node [above = 1cm] {$y(z)=z$} (yz);
\draw (p0) .. controls +(0:1cm) and +(205:1cm) .. (endgz) node [below] {$g(z)$} ;
\draw (y1) -- (yz1);
\draw (z1) -- (yz1);
How can this be "corrected" without giving absolute coordinates instead of relative ones to nodes? I find it very attractive to not always give absolute coordinates as this makes the image much more adaptable for future and generalized use.
You can change the inner sep:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] at(0,0) (origin) {};
\node[below = 0.0cm of origin]{$(0,0)$};
\node[above = 3cm of origin] (y) {$y$};
\node[right = 3cm of origin] (z) {$z$};
\node[above = 2cm of origin, left] (y1) {$1$};
\node[right = 2cm of origin, below] (z1) {$1$};
\node[inner sep=0pt,right = 2cm of y1] (yz1) {};
\node[above = 2.5cm of z] (endgz) {};
\node[above = 3cm of z] (yz) {};
\node[inner sep=0pt,above = 1cm of origin] (p0) {};
\draw[fill](p0) circle(0.06cm);
\node[left=0cm of p0]{$g(0)=p0$};
\draw[fill](yz1) circle(0.06cm);
\draw[->,thick] (0,0) -- (y);
\draw[->,thick] (0,0) -- (z);
\draw (origin) -- node [above = 1cm] {$y(z)=z$} (yz);
\draw (p0) .. controls +(0:1cm) and +(205:1cm) .. (endgz) node [below] {$g(z)$} ;
\draw (y1) -- (yz1);
\draw (z1) -- (yz1);
\end{tikzpicture}
\end{document}
I have a openscad object that I would like to add an angle / angled profile to the bottom of a barbed object all the way around.
Original (what's currently created):
What I would like: (have the bottom all the way around not be flat but at an angle / angle profile like 45,50,60...)
Code:
////////////////////////////////////////////////////////
// Created by Paul Tibble - 18/7/19 //
// https://www.thingiverse.com/Paul_Tibble/about //
// Please consider tipping, if you find this useful. //
////////////////////////////////////////////////////////
$fn = 100*1;
// Outer Diameter (bottom)
outer_diameter_1 = 15;
// Wall Thickness (bottom)
wall_thickness_1 = 2;
// Rib Thickness (bottom), set to Zero to remove
barb_size_1 = 0.5;
// Length (bottom)
length_1 = 15;
// Outer Diameter (top), should be smaller than or equal to Outer Diameter (bottom)
outer_diameter_2 = 12;
// Wall Thickness (top)
wall_thickness_2 = 1;
// Rib Thickness (top), set to Zero to remove
barb_size_2 = 0.5;
// Length (top)
length_2 = 15;
// Middle Diameter
mid_diameter = 17;
// Middle Length
mid_length = 5;
//do not change these
inner_diameter_1 = outer_diameter_1 - (wall_thickness_1*2);
inner_diameter_2 = outer_diameter_2 - (wall_thickness_2*2);
module create_profile() {
////////
// Middle
///////
polygon(points=[[inner_diameter_1/2,length_1],[mid_diameter/2,length_1],[mid_diameter/2,length_1+mid_length],[inner_diameter_2/2,length_1+mid_length]]);
//////
//length 1
/////
translate([inner_diameter_1/2,0,0])square([wall_thickness_1,length_1]);
//barb 1
translate([outer_diameter_1/2,0,0])polygon(points=[[0,0],[0,(length_1/5)],[barb_size_1,(length_1/5)]]);
//barb 2
translate([outer_diameter_1/2,length_1*0.25,0])polygon(points=[[0,0],[0,(length_1/5)],[barb_size_1,(length_1/5)]]);
//barb 3
translate([outer_diameter_1/2,length_1*0.5,0])polygon(points=[[0,0],[0,(length_1/5)],[barb_size_1,(length_1/5)]]);
//////
//length 2
/////
translate([inner_diameter_2/2,length_1+mid_length,0])square([wall_thickness_2,length_2]);
//rib 1
translate([outer_diameter_2/2,(length_1+mid_length+length_2),0])polygon(points=[[0,0],[0,-1*(length_2/5)],[barb_size_2,-1*(length_2/5)]]);
//rib 2
translate([outer_diameter_2/2,(length_1+mid_length+length_2)-length_2*0.25,0])polygon(points=[[0,0],[0,-1*(length_2/5)],[barb_size_2,-1*(length_2/5)]]);
//rib 3
translate([outer_diameter_2/2,(length_1+mid_length+length_2)-length_2*0.5,0])polygon(points=[[0,0],[0,-1*(length_2/5)],[barb_size_2,-1*(length_2/5)]]);
}
rotate_extrude(angle = 360, convexity = 10) create_profile();
//create_profile();
just move the inner upper point of the barb- resp. the inner lower point of the rib-polygons (the y-value of the second point). To do this calculate the z-delta by tangens of the desired angle.
The code can be simplified by creating modules for barbs and ribs and placing them in for loops, here the modified code:
$fn = 100*1;
// Outer Diameter (bottom)
outer_diameter_1 = 15;
// Wall Thickness (bottom)
wall_thickness_1 = 2;
// Rib Thickness (bottom), set to Zero to remove
barb_size_1 = 0.5;
// Length (bottom)
length_1 = 15;
// Outer Diameter (top), should be smaller than or equal to Outer Diameter (bottom)
outer_diameter_2 = 12;
// Wall Thickness (top)
wall_thickness_2 = 1;
// Rib Thickness (top), set to Zero to remove
barb_size_2 = 0.5;
// Length (top)
length_2 = 15;
// Middle Diameter
mid_diameter = 17;
// Middle Length
mid_length = 5;
// barb angle
ba = 30;
//do not change these
// delta z
// tan(ba) = dz1/barb_size_1
dz1 = barb_size_1*tan(ba);
dz2 = barb_size_2*tan(ba);
inner_diameter_1 = outer_diameter_1 - (wall_thickness_1*2);
inner_diameter_2 = outer_diameter_2 - (wall_thickness_2*2);
module barb(dz) {
polygon(points=[[0, 0],[0, (length_1/5 + dz)],[barb_size_1, (length_1/5)]]);
}
module rib(dz) {
polygon(points=[[0, 0],[0,-1*(length_2/5 + dz)],[barb_size_2,-1*(length_2/5)]]);
}
module create_profile() {
// Middle
polygon(points=[[inner_diameter_1/2,length_1],[mid_diameter/2,length_1],[mid_diameter/2,length_1+mid_length],[inner_diameter_2/2,length_1+mid_length]]);
//length 1
translate([inner_diameter_1/2,0,0])square([wall_thickness_1,length_1]);
//barbs
for (z = [0, 0.25, 0.5]) {
translate([outer_diameter_1/2, length_1*z, 0]) barb(dz1);
}
//length_2
translate([inner_diameter_2/2,length_1+mid_length,0])square([wall_thickness_2,length_2]);
//ribs
for (z = [0, 0.25, 0.5]) {
translate([outer_diameter_2/2,(length_1+mid_length+length_2)-length_2*z,0]) rib(dz2);
}
}
rotate_extrude(angle = 360, convexity = 10) create_profile();
//create_profile();
looks like this:
Here's something that the Openscad list helped me piece together that helps.
////////////////////////////////////////////////////////
// Created by Paul Tibble - 18/7/19 + Openscad group 2021 //
// https://www.thingiverse.com/Paul_Tibble/about //
// Please consider tipping, if you find this useful. //
////////////////////////////////////////////////////////
$fn = 100*1;
// Outer Diameter (bottom)
outer_diameter_1 = 15;
// Wall Thickness (bottom)
wall_thickness_1 = 2;
// Rib Thickness (bottom), set to Zero to remove
barb_size_1 = 0.5;
// Length (bottom)
length_1 = 15;
// Outer Diameter (top), should be smaller than or equal to Outer Diameter (bottom)
outer_diameter_2 = 12;
// Wall Thickness (top)
wall_thickness_2 = 1;
// Rib Thickness (top), set to Zero to remove
barb_size_2 = 0.5;
// Length (top)
length_2 = 15;
// Middle Diameter
mid_diameter = 17;
// Middle Length
mid_length = 5;
// Barb Angles (90 deg) makes it flat 20 to 30
barb_angle = 30; // adjust to get angle you want. 90 or 0 makes it flat rt
// Barb Angles (90 deg) makes it flat 20 to 30
mid_barb_angle = 30; // adjust to get angle you want. 90 or 0 makes it flat rt
barb_angle_tmp_1 = length_1 / barb_angle;
barb_angle_tmp_2 = length_2 / barb_angle;
mid_barb_angle_tmp_1 = mid_diameter / mid_barb_angle - (mid_diameter/2);
//do not change these
inner_diameter_1 = outer_diameter_1 - (wall_thickness_1*2);
inner_diameter_2 = outer_diameter_2 - (wall_thickness_2*2);
module create_profile() {
////////
// Middle
///////
polygon(points=[[inner_diameter_1/2,length_1+mid_barb_angle_tmp_1],[mid_diameter/2,length_1],[mid_diameter/2,length_1+mid_length],[inner_diameter_2/2,length_1+mid_length]]);
//////
//length 1
/////
translate([inner_diameter_1/2,0,0])square([wall_thickness_1,length_1]);
//barb 1
translate([outer_diameter_1/2,0,0])polygon(points=[[0,0],[0,(length_1/5+barb_angle_tmp_1)],[barb_size_1,(length_1/5)]]);
//barb 2
translate([outer_diameter_1/2,length_1*0.25,0])polygon(points=[[0,0],[0,(length_1/5+barb_angle_tmp_1)],[barb_size_1,(length_1/5)]]);
//barb 3
translate([outer_diameter_1/2,length_1*0.5,0])polygon(points=[[0,0],[0,(length_1/5+barb_angle_tmp_1)],[barb_size_1,(length_1/5)]]);
//////
//length 2
/////
translate([inner_diameter_2/2,length_1+mid_length,0])square([wall_thickness_2,length_2]);
//rib 1
translate([outer_diameter_2/2,(length_1+mid_length+length_2),0])polygon(points=[[0,0],[0,-1*(length_2/5+barb_angle_tmp_2)],[barb_size_2,-1*(length_2/5)]]);
//rib 2
translate([outer_diameter_2/2,(length_1+mid_length+length_2)-length_2*0.25,0])polygon(points=[[0,0],[0,-1*(length_2/5+barb_angle_tmp_2)],[barb_size_2,-1*(length_2/5)]]);
//rib 3
translate([outer_diameter_2/2,(length_1+mid_length+length_2)-length_2*0.5,0])polygon(points=[[0,0],[0,-1*(length_2/5+barb_angle_tmp_2)],[barb_size_2,-1*(length_2/5)]]);
}
rotate_extrude(angle = 360, convexity = 10) create_profile();
//create_profile();
In Matlab, there is rectangle('Position',[x,y,w,h]) to draw a rectangle object, that w and h are a width and a height respectively (This link). While I try to draw a rectangle on an image using 4 corners: min_x, max_x, min_y and max_y that are specified in the following image.
Ex:
min_x = 193; max_x = 220; min_y = 168; max_y = 190;
I saw this link and like that, but they couldn't help me. Is there any way to draw a rectangle with 4 corners?
A = imresize( imread('peppers.png'),0.6);%resizing for better visibility
min_x = 193; max_x = 220; min_y = 168; max_y = 190;
x = min_x;
y = min_y;
w = max_x-min_x;
h = max_y-min_y;
imshow(A)
rectangle('Position',[x,y,w,h],'EdgeColor','r','Linewidth',3);
% Or insert shape to bitmap:
% B = insertShape(A,'rectangle',[x,y,w,h]);
% imshow(B)
I have this code:
x = 1:1:1000;
Hw = 2;
T1 = 60;
L1 = 100;
eta1 = (Hw/2)*(sin(2*pi*((x/L1)-(1/T1))));
units_out ='centimeters';
width = 8;
height = 6;
typefon = 'Times';
fsize_axis = 8;
fsize_label = 10;
fig1 = figure;
h0 = plot(x, eta1,'r');
ylim([-2 2]);
set(gca,'FontName',typefon,'FontSize',fsize_axis,'FontWeight','bold');
title('Water wave 1');
xl0 = xlabel('x (m)');
set(xl0,'FontSize',fsize_label);
yl0 =ylabel('\eta (m)');
set(yl0,'FontSize',fsize_label);
pos =get(gcf,'Position');
pos(3) = width;
pos(4) = height;
set(gcf,'units','centimeters','Position',pos);
set(gca,'LooseInset',max(get(gca,'TightInset'), 0.02))
set(gcf,'PaperPositionMode','auto');
print('my_figure', '-dpng', '-r600');
delete(fig1);
winopen('my_figure.png');
I got an image of: 8.0 x 6.0 cm; 3.15 x 2.36 inches (I expected this size), but if I only modify the formattype to –djpeg of print function, I got a graphics file of: 66.7 x 50.0 cm; 26.25 x 19.68 inches. Why does the size change? How can I compute the size of the image, in centimeters, taking into account the resolution of the image?
I would like to move the y-axis labels to the left side of heatmap.2. (This is similar, but not the same, as the question regarding moving the axis on heatmap)
While I am able to move the axis by editing line 290 of the heatmap.2 function, it the values then overwrite the actual heatmap.
if (is.null(srtRow) && is.null(colRow)) {
axis(4, iy, labels = labRow, las = 2, line = -0.5 + offsetRow,
tick = 0, cex.axis = cexRow, hadj = adjRow[1], padj = adjRow[2])
}
else {
if (is.null(srtRow) || is.numeric(srtRow)) {
xpd.orig <- par("xpd")
par(xpd = NA)
ypos <- axis(4, iy, labels = rep("", nr), las = 2, #change
line = -0.5, tick = 0)
text(x = par("usr")[2] + (1 + offsetRow) * strwidth("M"),
y = ypos, labels = labRow, adj = adjRow, cex = cexRow,
srt = srtRow, col = colRow)
par(xpd = xpd.orig)
}
I tried moving the location of the heatmap.2 by mucking about with the lwid and lhei options, but the overwrite problem persisted.
Thank you
Eric