Seite 1 von 1

Funktionsplot, x-Label aus Daten

Verfasst: Di 29. Okt 2013, 13:48
von mar.kus
Hallo,

ich möchte einen Verlauf einer Funktion inkl. Spannweite darstellen. Nach etwas suchen habe ich endlich eine Lösung gefunden.

Zum Abschluss habe ich noch das Problem, dass ich auf dem Label der x-Achse nur jeden n-ten Wert darstellen möchte. Wie mache ich das? Das Gitter soll sich automatisch anpassen. Momentan scheinen die Labels nicht zu der gezeichneten Funktion zu passen.

Gibt es eine Möglichkeit die Abstand zwischen zwei Werten auf der x-Achse zu definieren, so dass pdfplots automatisch die Anzahl an möglichen Labels berechnet und zwar so, dass diese sich nicht überschneiden.

Minimalbsp.:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\pgfplotstableread{
X	time	label	A	B	C	D	E	F	G	min	Spannweite
1	1983	{1983 - 2012}	0	0	0	0	0	0	0	0	0
2	1984	{1984 - 2013}	-0.017121509	-0.033407736	-0.043991815	-0.041381073	-0.016848438	-0.01975182	-0.024115843	-0.086196319	0.140966659
3	1985	{1985 - 2014}	0.019168814	-0.012487143	-0.022193156	-0.015052538	0.024497873	0.0092011	-0.001395904	-0.073354262	0.191223186
4	1986	{1986 - 2015}	0.010553887	-0.042213326	-0.049313848	-0.027375214	0.021355285	0.010324509	0.004243064	-0.122494299	0.255413153
5	1987	{1987 - 2016}	-0.023699411	-0.086672055	-0.086567445	-0.049278918	-0.004004168	-0.006249814	-0.000485287	-0.155460783	0.278589525
6	1988	{1988 - 2017}	-0.011886025	-0.08330078	-0.080887601	-0.045744396	0.013681493	0.009097842	0.011756454	-0.153528005	0.290258406
7	1989	{1989 - 2018}	-0.024541182	-0.092471578	-0.096826026	-0.069472379	0.013713619	-0.016252304	-0.016818474	-0.155341913	0.292655885
8	1990	{1990 - 2019}	-0.00487213	-0.048878959	-0.067800322	-0.057844643	0.047403555	-0.009876466	-0.004226095	-0.139123335	0.32474989
9	1991	{1991 - 2020}	0.035935224	0.004910143	-0.021977269	-0.010510656	0.085810092	0.030781789	0.027625115	-0.082000587	0.291281542
10	1992	{1992 - 2021}	0.052810952	0.037344474	0.020971934	0.014958498	0.094824217	0.050443658	0.052110916	-0.068387719	0.328695796
11	1993	{1993 - 2022}	0.048162089	0.035307546	0.012143249	-0.002588001	0.094532826	0.028854705	0.028604777	-0.106878338	0.363469069
12	1994	{1994 - 2023}	0.078112382	0.053990896	0.03202067	0.016204563	0.115955317	0.040331221	0.047539245	-0.091859473	0.342772934
13	1995	{1995 - 2024}	0.142922917	0.141157734	0.119961698	0.079482743	0.180735535	0.09577619	0.105475763	0.006035939	0.301282051
14	1996	{1996 - 2025}	0.171052784	0.179799901	0.147651521	0.086928911	0.213724998	0.111784405	0.106847191	-0.030107748	0.358633431
15	1997	{1997 - 2026}	0.165456042	0.181184872	0.153591158	0.095922745	0.217267418	0.11636918	0.115100914	-0.033022123	0.372371643
16	1998	{1998 - 2027}	0.224240187	0.222951116	0.190423168	0.143155332	0.269765063	0.185907948	0.170090426	0.016558039	0.380009303
17	1999	{1999 - 2028}	0.223616776	0.226696304	0.205100607	0.155756066	0.261785525	0.176642682	0.16036626	0.029030541	0.327152522
18	2000	{2000 - 2029}	0.210237372	0.227171501	0.19845006	0.142596592	0.268970306	0.154867414	0.137484693	0.012038343	0.329654591
19	2001	{2001 - 2030}	0.2300689	0.237031319	0.212801484	0.164336768	0.293214931	0.187869427	0.170925841	0.083072499	0.26578724
20	2002	{2002 - 2031}	0.281759088	0.28158237	0.263572235	0.215203865	0.338041061	0.240563645	0.226988863	0.121990692	0.259313934
21	2003	{2003 - 2032}	0.291069512	0.286507696	0.272198638	0.223680197	0.35387195	0.253847404	0.234544591	0.188787783	0.208484208
22	2004	{2004 - 2033}	0.279696016	0.256946107	0.253783435	0.220418141	0.334292877	0.239954812	0.223443376	0.145399019	0.243891953
23	2005	{2005 - 2034}	0.299570795	0.270056399	0.273249056	0.241981287	0.356514012	0.268356568	0.254467148	0.205903041	0.208363089
24	2006	{2006 - 2035}	0.309615651	0.288330802	0.295104247	0.251328015	0.374036303	0.26990925	0.257330405	0.189790925	0.218600357
25	2007	{2007 - 2036}	0.334396198	0.325301036	0.33266742	0.276373125	0.406220708	0.290316854	0.285009109	0.164827036	0.292418732
26	2008	{2008 - 2037}	0.371887935	0.370445833	0.377481111	0.316790364	0.436335293	0.324749389	0.316231169	0.195754904	0.281052286
27	2009	{2009 - 2038}	0.390667456	0.389525845	0.394594888	0.335774503	0.460629342	0.346089636	0.34321401	0.184665097	0.37308909
28	2010	{2010 - 2039}	0.433736661	0.427886718	0.435651017	0.373323563	0.498610897	0.384062949	0.386534691	0.1829685	0.473446551
29	2011	{2011 - 2040}	0.473674668	0.475968631	0.485528631	0.421916836	0.534010866	0.428048737	0.433321488	0.260294957	0.427565888
30	2012	{2012 - 2041}	0.46168758	0.468334961	0.482403125	0.423924017	0.517868011	0.425154602	0.43507744	0.230756039	0.48193625
31	2013	{2013 - 2042}	0.489269937	0.486926286	0.492285659	0.435349385	0.549691709	0.447369925	0.458191789	0.253839723	0.461647824
32	2014	{2014 - 2043}	0.531425078	0.532379389	0.536581791	0.47675367	0.600494315	0.484484524	0.493143287	0.213728132	0.602720808
33	2015	{2015 - 2044}	0.555327202	0.556650037	0.562337987	0.491977778	0.618779023	0.494678952	0.508404903	0.228674333	0.619103155
34	2016	{2016 - 2045}	0.578895348	0.59554575	0.592775176	0.518415477	0.649811829	0.512698601	0.524595134	0.236213715	0.616146512
35	2017	{2017 - 2046}	0.626806423	0.649842415	0.648197846	0.563925478	0.697474029	0.556888209	0.571052026	0.239529226	0.638046746
36	2018	{2018 - 2047}	0.665394097	0.694836343	0.691952978	0.606052624	0.743677475	0.597279404	0.616604513	0.192976858	0.751212912
37	2019	{2019 - 2048}	0.732525485	0.770616312	0.770732625	0.686651481	0.804595643	0.671722551	0.696548627	0.239398067	0.795997432
38	2020	{2020 - 2049}	0.741315034	0.78518986	0.783443389	0.698495025	0.808797061	0.683760755	0.711032203	0.24673281	0.779420334
39	2021	{2021 - 2050}	0.768481223	0.808276911	0.803749661	0.714082001	0.842087552	0.711349275	0.737789247	0.313184241	0.739605615
40	2022	{2022 - 2051}	0.774142054	0.806783362	0.794206577	0.714286281	0.848367335	0.71745826	0.749810838	0.227900328	0.877740603
41	2023	{2023 - 2052}	0.807467935	0.840161685	0.838013515	0.763509688	0.877910911	0.76380641	0.809288296	0.244797274	0.893231395
42	2024	{2024 - 2053}	0.873055245	0.910648463	0.900370973	0.82860762	0.948464718	0.837101181	0.87786714	0.327795198	0.872733752
43	2025	{2025 - 2054}	0.871693248	0.894911189	0.886821435	0.82948376	0.947331394	0.851130646	0.892213995	0.330872303	0.873132443
44	2026	{2026 - 2055}	0.890040304	0.916658705	0.907396126	0.852034206	0.968032715	0.869171063	0.911976626	0.370480916	0.859132109
45	2027	{2027 - 2056}	0.935158752	0.954043871	0.944781851	0.89614354	1.003763737	0.9191149	0.961000089	0.356866813	0.966984114
46	2028	{2028 - 2057}	0.964747939	0.992655695	0.994650352	0.948560021	1.026834143	0.952701095	1.014543608	0.353999987	1.062290385
47	2029	{2029 - 2058}	1.02780542	1.059577163	1.063601408	1.026900246	1.08967071	1.030712214	1.091669717	0.441944943	1.059194973
48	2030	{2030 - 2059}	1.077961853	1.113736581	1.119002072	1.082620752	1.135675016	1.081485366	1.143310615	0.520863122	0.974474534
49	2031	{2031 - 2060}	1.12399162	1.166127748	1.172771516	1.145775129	1.163675441	1.137910958	1.204792387	0.564064478	1.028258082
50	2032	{2032 - 2061}	1.156512553	1.212171712	1.215992495	1.183353654	1.19583324	1.182771146	1.249132814	0.568324834	1.043387999
51	2033	{2033 - 2062}	1.200269251	1.256172921	1.26474565	1.245100358	1.224293615	1.2378828	1.31317218	0.618161641	1.020545536
52	2034	{2034 - 2063}	1.276734381	1.345176945	1.354081728	1.336550766	1.29819637	1.336898704	1.426576743	0.692909391	1.090406215
53	2035	{2035 - 2064}	1.333744682	1.420582025	1.419341432	1.407193836	1.349149607	1.404676539	1.49495229	0.782396529	1.052227944
54	2036	{2036 - 2065}	1.358749546	1.451171887	1.44347115	1.434323898	1.380576478	1.433777801	1.51373013	0.837618724	0.995098306
55	2037	{2037 - 2066}	1.407008683	1.487133376	1.479235439	1.48157398	1.420729643	1.485819648	1.561326094	0.907409259	0.973023549
56	2038	{2038 - 2067}	1.464538073	1.540992362	1.536274624	1.551137957	1.469879596	1.55868312	1.643361684	0.914708849	1.107646534
57	2039	{2039 - 2068}	1.510456056	1.593473054	1.594111663	1.608358031	1.509483173	1.608986608	1.694286018	0.986079711	1.059236627
58	2040	{2040 - 2069}	1.535196309	1.628966279	1.630786895	1.647573208	1.528286957	1.647294063	1.730291243	1.016213673	1.069198311
59	2041	{2041 - 2070}	1.542021804	1.626232445	1.630791116	1.653617338	1.533654976	1.66308718	1.742306144	1.012641627	1.101786811
60	2042	{2042 - 2071}	1.574776594	1.66162872	1.664260913	1.689444617	1.564633882	1.692833981	1.778988745	1.071657369	1.079777211
61	2043	{2043 - 2072}	1.589206354	1.685235201	1.694288559	1.725515769	1.562262704	1.719714336	1.817459671	1.073886346	1.125601282
62	2044	{2044 - 2073}	1.610139551	1.709472451	1.723466639	1.75801086	1.571785286	1.751812193	1.861289172	1.066158613	1.18175934
63	2045	{2045 - 2074}	1.651266591	1.761986427	1.78424809	1.816319535	1.612314997	1.804049283	1.918019456	1.051068548	1.290479137
64	2046	{2046 - 2075}	1.684136986	1.795718468	1.818575311	1.852805218	1.645913643	1.849061663	1.961606069	1.093926152	1.318816495
65	2047	{2047 - 2076}	1.711950808	1.819729309	1.839285541	1.881449528	1.66566606	1.878737245	1.988798129	1.137228829	1.341085766
66	2048	{2048 - 2077}	1.741081487	1.833155525	1.855506051	1.912630145	1.684414064	1.91841873	2.026677243	1.187224052	1.308854162
67	2049	{2049 - 2078}	1.759173884	1.846179708	1.870001372	1.935729642	1.702528461	1.938429043	2.053880151	1.236627527	1.308212202
68	2050	{2050 - 2079}	1.821957245	1.914450093	1.947766231	2.013564609	1.756787031	2.006210123	2.125393131	1.281682677	1.319406191
69	2051	{2051 - 2080}	1.832650628	1.924405464	1.963778459	2.034888677	1.75935254	2.018893364	2.144566063	1.253213059	1.417515112
70	2052	{2052 - 2081}	1.90147542	2.002501579	2.051485079	2.126406657	1.81777238	2.101150118	2.225565935	1.361188477	1.357525234
71	2053	{2053 - 2082}	1.936002274	2.043579035	2.089530512	2.161532165	1.842456734	2.140095678	2.259735341	1.362976623	1.422588109
72	2054	{2054 - 2083}	1.962039794	2.082388799	2.133978897	2.199473727	1.860964215	2.175732679	2.299298433	1.371589355	1.453152498
73	2055	{2055 - 2084}	2.037083597	2.166391525	2.220342437	2.286236855	1.919561624	2.252230442	2.382111422	1.445553043	1.534228553
74	2056	{2056 - 2085}	2.088158354	2.222277452	2.278936313	2.353751262	1.956487028	2.322201916	2.456862053	1.427092605	1.663122533
75	2057	{2057 - 2086}	2.128926834	2.264910644	2.325053151	2.410679486	1.985027714	2.384705614	2.533506258	1.420700918	1.78036235
76	2058	{2058 - 2087}	2.174894284	2.316286644	2.373102678	2.446371463	2.035668489	2.427278001	2.570489092	1.46141329	1.815386031
77	2059	{2059 - 2088}	2.224813794	2.368289771	2.422337384	2.498519042	2.078794771	2.478880385	2.629777314	1.482569498	1.848565951
78	2060	{2060 - 2089}	2.256399902	2.390228001	2.44583375	2.520596508	2.111910282	2.512277797	2.666205462	1.485835363	1.871982034
79	2061	{2061 - 2090}	2.311885686	2.44658055	2.50669335	2.572766083	2.171189322	2.554316472	2.71472186	1.55837305	1.875107792
80	2062	{2062 - 2091}	2.307906405	2.435937425	2.494213393	2.576779108	2.165999506	2.554712035	2.720327514	1.585094642	1.774181484
81	2063	{2063 - 2092}	2.358258356	2.475567742	2.53831209	2.624653649	2.21209766	2.611025184	2.782215061	1.632674514	1.786795595
82	2064	{2064 - 2093}	2.416522771	2.526194355	2.58626756	2.678588815	2.257695505	2.675913633	2.839162135	1.681057351	1.79271713
83	2065	{2065 - 2094}	2.442922663	2.546023786	2.613134878	2.703008614	2.285022945	2.692875561	2.857521291	1.70412459	1.768297303
84	2066	{2066 - 2095}	2.52341658	2.608100966	2.686074006	2.793995684	2.345479598	2.792135185	2.970881776	1.715426062	1.859875981
85	2067	{2067 - 2096}	2.544469934	2.625972414	2.712383344	2.824030395	2.354048424	2.821966616	3.006671715	1.722197173	1.906033824
86	2068	{2068 - 2097}	2.524215679	2.603371019	2.696820731	2.811816011	2.33496815	2.80536687	2.995734657	1.704771975	1.910714585
87	2069	{2069 - 2098}	2.553907755	2.622920639	2.727764864	2.862892013	2.361846429	2.848345051	3.055447638	1.747192521	1.933177842
88	2070	{2070 - 2099}	2.55515788	2.615621443	2.719432298	2.863752366	2.368219378	2.852742555	3.064741987	1.744131494	1.919366444
}\Data

\begin{document}
\begin{tikzpicture}
%\pgfplotstableread[col sep=semicolon]{data/datafilledcurves.csv}\Data

\begin{axis}[
    xticklabels from table={\Data}{label}, 
    xtick={0,5,...,88},
    xticklabel style={rotate=90,xshift=-0.4ex,anchor=mid east}, 
%   extra y ticks=0,
%    extra y tick style={grid=major, grid style={green!20,opacity=0.75}},
% y tick label style={/pgf/number format/1000 sep=},
    reverse legend, 
    legend pos=north west,
    legend entries={Spannweite, X},
    tiny,
	height=4cm,
	width=10cm, 
	ylabel={Änderung},
	xlabel={Test}, 
    	ymin=-0.5, ymax=4,
    	xmin=0, xmax=88,
	grid=major,
    	axis x line* = bottom,
	axis y line* = left
    ]
    
    \addplot [stack plots=y, fill=none, draw=none, forget plot] table [x=X,y=min]{\Data} \closedcycle;
    \addplot [stack plots=y, fill=gray!20, opacity=0.8, draw opacity=0, area legend] table [x=X,y=Spannweite]   {\Data} \closedcycle;
    	\addplot [stack plots=false, draw=black, thick]  table [x=X,y=A]   {\Data};

 
\end{axis}
\end{tikzpicture}

\end{document}
Danke

Verfasst: Di 29. Okt 2013, 17:22
von esdd
Hier ist ein Vorschlag, der aber ausnutzt, dass sich die Beschriftung aus den Werten von X ausrechnen lässt:
\documentclass[border=5mm]{standalone} 
\usepackage{selinput}\SelectInputMappings{adieresis={ä},germandbls={ß},Euro={€}} 
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.9} 

\pgfplotstableread{ 
...% wie oben
}\Data 

\begin{document} 
\begin{tikzpicture} 

\begin{axis}[ 
     xticklabel={\pgfmathparse{int(\tick+1982)}\pgfmathresult-\pgfmathparse{int(\tick+2011)}\pgfmathresult},
     xticklabel style={rotate=90,xshift=-0.4ex,anchor=mid east}, 
     reverse legend, 
     legend pos=north west, 
     legend entries={Spannweite, X}, 
     tiny, 
     height=4cm,width=10cm, 
     ylabel={Änderung},xlabel={Test}, 
     ymin=-0.5, ymax=4, 
     xmin=0, xmax=88, 
     grid=major, 
     axis x line* = bottom,axis y line* = left 
     ] 
     \addplot [stack plots=y, fill=none, draw=none, forget plot] table [x=X,y=min]{\Data} \closedcycle; 
     \addplot [stack plots=y, fill=gray!20, opacity=0.8, draw opacity=0, area legend] table [x=X,y=Spannweite]   {\Data} \closedcycle; 
     \addplot [stack plots=false, draw=black, thick]  table [x=X,y=A]   {\Data}; 
\end{axis} 
\end{tikzpicture} 

\end{document}
Gruß
Elke