Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
% Source: http://tex.stackexchange.com/a/69234/5645
2
\documentclass[varwidth=true, border=2pt]{standalone}
3
4
\usepackage{pgfplots}
5
\usepackage{tikz}
6
\usetikzlibrary{arrows, positioning, calc}
7
8
\begin{document}
9
\newcommand\shift{1.5}
10
11
\begin{tikzpicture}[scale=1]
12
\begin{axis}[
13
ybar,
14
ylabel={vaule},
15
ylabel style={at={(0.02,0.5)}, color=red},
16
xlabel={items},
17
legend style={at={(0.5,-0.15)},
18
anchor=north,legend columns=-1},
19
width=0.8*\textwidth,
20
height=9cm,
21
bar width=7pt,
22
symbolic x coords={
23
$x_1$,$x_2$,$x_3$,$x_4$,$x_5$,$x_6$, $x_7$, $x_8$,
24
$x_9$, $x_{10}$, $x_{11}$, $x_{12}$, $x_{13}$,
25
$x_{14}$, $x_{15}$
26
},
27
xtick=data,
28
scaled y ticks=base 10:-3,
29
axis y line*=left,
30
%nodes near coords,
31
%nodes near coords align={vertical},
32
]
33
\addplot[red, fill=red!15, shift={(-\shift,0)}] coordinates {
34
($x_1$,96000) ($x_2$,126000) ($x_3$,115000)
35
($x_4$,125000) ($x_5$,123000) ($x_6$, 123000)
36
($x_7$, 112000) ($x_8$, 111000) ($x_9$, 110000)
37
($x_{10}$, 110000) ($x_{11}$, 120000)
38
($x_{12}$, 98000) ($x_{13}$, 130000)
39
($x_{14}$, 87000) ($x_{15}$, 97000)};
40
\end{axis}
41
\begin{axis}[
42
ybar,
43
ylabel={weight},
44
ylabel style={at={(1.25,0.5)}, color=blue},
45
legend style={at={(0.7,-0.15)},
46
anchor=north,legend columns=-1},
47
width=0.8*\textwidth,
48
height=9cm,
49
bar width=7pt,
50
symbolic x coords={
51
$x_1$,$x_2$,$x_3$,$x_4$,$x_5$,$x_6$, $x_7$, $x_8$,
52
$x_9$, $x_{10}$, $x_{11}$, $x_{12}$, $x_{13}$,
53
$x_{14}$, $x_{15}$
54
},
55
xtick=data,
56
%nodes near coords,
57
%nodes near coords align={vertical},
58
axis y line*=right,
59
axis x line=none,
60
]
61
\addplot +[shift={(\shift,0)}] coordinates {($x_1$,27)
62
($x_2$,21) ($x_3$,27) ($x_4$,15) ($x_5$,19)
63
($x_6$, 46) ($x_7$, 47) ($x_8$, 32) ($x_9$, 14)
64
($x_{10}$, 20) ($x_{11}$, 50) ($x_{12}$, 19)
65
($x_{13}$, 22) ($x_{14}$, 50) ($x_{15}$, 46)};
66
\end{axis}
67
\end{tikzpicture}
68
\end{document}
69
70