Hello fellows and folks!
I am working with python and I need to draw the following picture in latex by using the values from the variables. They are a ton, so it is not like the usual stuff where I plot 10 (x,y) points. How can I use those file and get the same plot as in the picture
It looks something like this:
Users' csv file structure:
user_index user_counts
0 20
0.000165562913907 20
0.000331125827815 20
0.000496688741722 20
0.000662251655629 20
0.000827814569536 20
0.000993377483444 20
0.001158940397351 20
0.001324503311258 20
0.001490066225166 20
0.001655629139073 20
0.00182119205298 20
0.247682119205298 44
0.247847682119205 44
0.248013245033113 44
0.24817880794702 44
0.248344370860927 44
0.248509933774834 44
0.248675496688742 44
0.248841059602649 44
0.249006622516556 44
0.249172185430464 44
0.249337748344371 44
0.249503311258278 44
0.249668874172185 44
0.249834437086093 44
0.25 44
0.250165562913907 44
0.250331125827815 44
0.250496688741722 44
0.250662251655629 44
0.250827814569536 44
0.250993377483444 44
0.251158940397351 44
0.251324503311258 44
0.251490066225166 44
0.251655629139073 44
0.25182119205298 44
0.251986754966887 45
0.252152317880795 45
0.252317880794702 45
0.252483443708609 45
0.252649006622517 45
0.252814569536424 45
0.252980132450331 45
0.253145695364238 45
0.253311258278146 45
0.253476821192053 45
0.25364238410596 45
0.253807947019868 45
0.253973509933775 45
0.254139072847682 45
0.254304635761589 45
0.254470198675497 45
0.254635761589404 45
0.254801324503311 45
0.254966887417219 45
0.255132450331126 45
0.255298013245033 45
0.25546357615894 45
0.255629139072848 45
0.255794701986755 45
0.255960264900662 45
0.25612582781457 45
0.256291390728477 45
0.256456953642384 45
0.256622516556291 45
0.256788079470199 45
0.256953642384106 45
0.257119205298013 45
0.25728476821192 45
0.257450331125828 45
0.257615894039735 45
0.257781456953642 45
0.25794701986755 45
0.258112582781457 45
0.258278145695364 45
0.258443708609271 45
0.258609271523179 46
0.258774834437086 46
0.258940397350993 46
0.259105960264901 46
0.259271523178808 46
0.259437086092715 46
0.259602649006622 46
0.25976821192053 46
0.259933774834437 46
0.260099337748344 46
0.260264900662252 46
0.260430463576159 46
0.260596026490066 46
0.260761589403974 46
0.260927152317881 46
0.261092715231788 46
0.261258278145695 46
0.261423841059603 46
0.26158940397351 46
0.261754966887417 46
0.261920529801325 46
0.262086092715232 46
0.262251655629139 46
0.262417218543046 46
0.262582781456954 46
0.262748344370861 46
0.262913907284768 46
0.263079470198675 46
0.263245033112583 46
0.26341059602649 46
0.263576158940397 46
0.263741721854305 46
0.263907284768212 46
0.264072847682119 46
0.264238410596026 46
0.264403973509934 46
0.264569536423841 46
0.264735099337748 46
0.264900662251656 46
0.265066225165563 46
0.26523178807947 46
0.265397350993377 46
0.265562913907285 46
0.265728476821192 46
0.265894039735099 46
0.266059602649007 46
0.266225165562914 47
0.266390728476821 47
0.266556291390728 47
0.266721854304636 47
0.266887417218543 47
0.26705298013245 47
0.267218543046358 47
0.267384105960265 47
0.267549668874172 47
0.267715231788079 47
0.267880794701987 47
0.268046357615894 47
0.268211920529801 47
0.268377483443709 47
0.268543046357616 47
0.268708609271523 47
0.26887417218543 47
0.269039735099338 47
0.269205298013245 47
0.269370860927152 47
0.26953642384106 47
0.269701986754967 47
0.269867549668874 47
0.270033112582781 47
0.270198675496689 47
0.270364238410596 47
0.270529801324503 47
0.270695364238411 47
0.270860927152318 47
0.271026490066225 47
0.271192052980132 47
0.27135761589404 47
0.271523178807947 47
0.271688741721854 47
0.271854304635762 47
0.272019867549669 47
0.272185430463576 47
0.272350993377483 47
0.272516556291391 47
0.272682119205298 47
0.272847682119205 47
0.273013245033113 47
0.27317880794702 47
0.273344370860927 47
0.273509933774834 47
0.273675496688742 47
0.273841059602649 47
0.274006622516556 47
0.274172185430464 47
0.274337748344371 47
0.274503311258278 47
0.274668874172185 47
0.274834437086093 47
0.275 47
0.275165562913907 47
0.275331125827815 48
0.275496688741722 48
0.275662251655629 48
0.275827814569536 48
0.275993377483444 48
0.276158940397351 48
0.276324503311258 48
0.276490066225166 48
0.276655629139073 48
0.27682119205298 48
0.276986754966887 48
0.277152317880795 48
0.277317880794702 48
0.277483443708609 48
0.277649006622517 48
0.277814569536424 48
0.277980132450331 48
0.278145695364238 48
0.278311258278146 48
0.278476821192053 48
0.27864238410596 48
0.278807947019868 48
0.278973509933775 48
0.279139072847682 48
0.279304635761589 48
0.279470198675497 48
0.279635761589404 48
0.279801324503311 48
0.279966887417219 48
0.280132450331126 48
0.280298013245033 48
0.28046357615894 48
0.280629139072848 48
0.280794701986755 48
0.280960264900662 48
0.281125827814569 48
0.281291390728477 48
0.281456953642384 48
0.281622516556291 48
0.281788079470199 48
0.281953642384106 48
0.282119205298013 48
0.282284768211921 48
0.282450331125828 48
0.282615894039735 48
0.282781456953642 48
0.28294701986755 48
0.283112582781457 48
0.283278145695364 48
0.283443708609272 48
0.283609271523179 48
0.283774834437086 49
0.283940397350993 49
0.284105960264901 49
0.284271523178808 49
0.284437086092715 49
0.284602649006622 49
0.28476821192053 49
0.284933774834437 49
0.285099337748344 49
0.285264900662252 49
0.285430463576159 49
0.285596026490066 49
0.285761589403973 49
0.285927152317881 49
0.286092715231788 49
0.286258278145695 49
0.286423841059603 49
0.28658940397351 49
0.286754966887417 49
0.286920529801324 49
0.287086092715232 49
0.287251655629139 49
0.287417218543046 49
0.287582781456954 49
0.287748344370861 49
0.287913907284768 49
0.288079470198676 49
0.288245033112583 49
0.28841059602649 49
0.288576158940397 50
0.288741721854305 50
0.288907284768212 50
0.289072847682119 50
0.289238410596026 50
0.289403973509934 50
0.289569536423841 50
0.289735099337748 50
0.289900662251656 50
0.290066225165563 50
0.29023178807947 50
0.290397350993377 50
0.290562913907285 50
0.290728476821192 50
0.290894039735099 50
0.291059602649007 50
0.291225165562914 50
0.291390728476821 50
0.291556291390728 50
0.291721854304636 50
0.291887417218543 50
0.29205298013245 50
0.292218543046358 50
0.292384105960265 50
0.292549668874172 50
0.292715231788079 50
0.292880794701987 50
0.293046357615894 50
0.293211920529801 50
0.293377483443709 50
0.293543046357616 50
0.293708609271523 50
0.29387417218543 50
0.294039735099338 50
0.294205298013245 50
0.294370860927152 50
0.29453642384106 50
0.294701986754967 50
0.294867549668874 50
0.295033112582781 50
0.295198675496689 50
0.295364238410596 50
0.295529801324503 50
0.295695364238411 50
0.295860927152318 50
0.296026490066225 50
0.296192052980133 50
0.29635761589404 50
0.296523178807947 50
0.296688741721854 50
0.296854304635762 51
0.297019867549669 51
0.297185430463576 51
0.297350993377483 51
0.297516556291391 51
0.297682119205298 51
0.297847682119205 51
0.298013245033113 51
0.29817880794702 51
0.298344370860927 51
0.298509933774834 51
0.298675496688742 51
0.298841059602649 51
0.299006622516556 51
0.299172185430464 51
0.299337748344371 51
0.299503311258278 51
0.299668874172185 51
0.299834437086093 51
0.3 51
0.300165562913907 51
0.300331125827815 51
0.300496688741722 51
0.300662251655629 51
0.300827814569536 51
0.300993377483444 51
0.301158940397351 51
0.301324503311258 51
0.301490066225166 51
0.301655629139073 51
0.30182119205298 51
0.301986754966887 51
0.302152317880795 51
0.302317880794702 51
0.302483443708609 51
0.302649006622517 51
0.302814569536424 51
0.302980132450331 51
0.303145695364238 51
0.303311258278146 51
0.303476821192053 51
0.30364238410596 51
0.303807947019868 52
0.303973509933775 52
0.304139072847682 52
0.304304635761589 52
0.304470198675497 52
0.304635761589404 52
0.304801324503311 52
0.304966887417219 52
0.305132450331126 52
0.305298013245033 52
0.30546357615894 52
0.305629139072848 52
0.305794701986755 52
0.305960264900662 52
0.30612582781457 52
0.306291390728477 52
0.306456953642384 52
0.306622516556291 52
0.306788079470199 52
0.306953642384106 52
0.307119205298013 52
0.30728476821192 52
0.307450331125828 52
0.307615894039735 52
0.307781456953642 52
0.30794701986755 52
0.308112582781457 52
0.308278145695364 52
0.308443708609271 52
0.308609271523179 52
0.308774834437086 52
0.308940397350993 52
0.309105960264901 52
0.309271523178808 52
0.309437086092715 52
0.309602649006622 52
0.30976821192053 52
0.309933774834437 52
0.310099337748344 52
0.310264900662252 53
0.310430463576159 53
0.310596026490066 53
0.310761589403973 53
0.310927152317881 53
0.311092715231788 53
0.311258278145695 53
0.311423841059603 53
0.31158940397351 53
0.311754966887417 53
0.311920529801324 53
0.312086092715232 53
0.312251655629139 53
0.312417218543046 53
0.312582781456954 53
0.312748344370861 53
0.312913907284768 53
0.313079470198675 53
0.313245033112583 53
0.31341059602649 53
0.313576158940397 53
0.313741721854305 53
0.313907284768212 53
0.314072847682119 53
0.314238410596026 53
0.314403973509934 53
0.314569536423841 53
0.314735099337748 53
0.314900662251656 53
0.315066225165563 53
0.31523178807947 53
0.315397350993377 53
0.315562913907285 53
0.315728476821192 53
0.315894039735099 53
0.316059602649007 54
0.316225165562914 54
0.316390728476821 54
0.316556291390728 54
0.316721854304636 54
0.316887417218543 54
0.31705298013245 54
0.317218543046358 54
0.317384105960265 54
0.317549668874172 54
0.317715231788079 54
0.317880794701987 54
0.318046357615894 54
0.318211920529801 54
0.318377483443709 54
0.318543046357616 54
0.318708609271523 54
0.31887417218543 54
0.319039735099338 54
0.319205298013245 54
0.319370860927152 54
0.31953642384106 54
0.319701986754967 54
0.319867549668874 54
0.320033112582781 54
0.320198675496689 54
0.320364238410596 54
0.320529801324503 54
0.320695364238411 54
0.320860927152318 54
0.321026490066225 55
0.321192052980132 55
0.32135761589404 55
0.321523178807947 55
0.321688741721854 55
0.321854304635762 55
0.322019867549669 55
0.322185430463576 55
0.322350993377483 55
0.322516556291391 55
0.322682119205298 55
0.322847682119205 55
0.323013245033113 55
0.32317880794702 55
0.323344370860927 55
0.323509933774834 55
0.323675496688742 55
0.323841059602649 55
0.324006622516556 55
0.324172185430464 55
0.324337748344371 55
0.324503311258278 55
0.324668874172185 55
0.324834437086093 55
0.325 55
0.325165562913907 55
0.325331125827815 55
0.325496688741722 55
0.325662251655629 55
0.325827814569536 55
0.325993377483444 55
0.326158940397351 55
0.326324503311258 55
0.326490066225166 55
0.326655629139073 55
0.32682119205298 55
0.326986754966887 55
Movies' csv file structure:
user_index user_counts
0 20
0.000165562913907 20
0.000331125827815 20
0.000496688741722 20
0.000662251655629 20
0.000827814569536 20
0.000993377483444 20
0.001158940397351 20
0.001324503311258 20
0.001490066225166 20
0.001655629139073 20
0.00182119205298 20
0.001986754966887 20
0.002152317880795 20
0.002317880794702 20
0.002483443708609 20
0.002649006622517 20
0.002814569536424 20
0.002980132450331 20
0.003145695364238 20
0.003311258278146 20
0.003476821192053 20
0.00364238410596 20
0.003807947019868 20
0.003973509933775 20
0.004139072847682 20
0.004304635761589 20
0.004470198675497 20
0.004635761589404 20
0.004801324503311 20
0.004966887417219 20
0.005132450331126 20
0.005298013245033 20
0.00546357615894 20
0.005629139072848 20
0.005794701986755 20
0.005960264900662 20
0.00612582781457 20
0.006291390728477 20
0.006456953642384 20
0.006622516556291 20
0.006788079470199 20
0.006953642384106 20
0.007119205298013 20
0.007284768211921 20
0.007450331125828 20
0.007615894039735 20
0.007781456953642 20
0.00794701986755 20
0.008112582781457 20
0.008278145695364 20
0.008443708609272 20
0.008609271523179 20
0.008774834437086 20
0.008940397350993 20
0.009105960264901 20
0.009271523178808 20
0.009437086092715 20
0.009602649006623 20
0.00976821192053 20
0.009933774834437 20
0.010099337748344 20
0.010264900662252 20
0.010430463576159 20
0.010596026490066 20
0.010761589403974 20
0.010927152317881 20
0.011092715231788 20
0.011258278145695 20
0.011423841059603 20
0.01158940397351 20
0.011754966887417 20
0.011920529801325 20
0.012086092715232 20
0.012251655629139 20
0.012417218543046 20
0.012582781456954 20
0.012748344370861 20
0.012913907284768 20
0.013079470198676 20
0.013245033112583 20
0.01341059602649 20
0.013576158940397 20
0.013741721854305 20
0.013907284768212 20
0.014072847682119 20
0.014238410596027 21
0.014403973509934 21
0.014569536423841 21
0.014735099337748 21
0.014900662251656 21
0.015066225165563 21
0.01523178807947 21
0.015397350993378 21
0.015562913907285 21
0.015728476821192 21
0.015894039735099 21
0.016059602649007 21
0.016225165562914 21
0.016390728476821 21
0.016556291390729 21
0.016721854304636 21
0.016887417218543 21
0.01705298013245 21
0.017218543046358 21
0.017384105960265 21
0.017549668874172 21
0.01771523178808 21
0.017880794701987 21
0.018046357615894 21
0.018211920529801 21
0.018377483443709 21
0.018543046357616 21
0.018708609271523 21
0.018874172185431 21
0.019039735099338 21
0.019205298013245 21
0.019370860927152 21
0.01953642384106 21
0.019701986754967 21
0.019867549668874 21
0.020033112582782 21
0.020198675496689 21
0.020364238410596 21
0.020529801324503 21
0.020695364238411 21
0.020860927152318 21
0.021026490066225 21
0.021192052980133 21
0.02135761589404 21
0.021523178807947 21
0.021688741721854 21
0.021854304635762 21
0.022019867549669 21
0.022185430463576 21
0.022350993377484 21
0.022516556291391 21
0.022682119205298 21
0.022847682119205 21
0.023013245033113 21
0.02317880794702 21
0.023344370860927 21
0.023509933774835 21
0.023675496688742 21
0.023841059602649 21
0.024006622516556 21
0.024172185430464 21
0.024337748344371 21
0.024503311258278 21
0.024668874172186 21
0.024834437086093 21
0.025 21
0.025165562913907 21
0.025331125827815 21
0.025496688741722 21
0.025662251655629 21
0.025827814569537 21
0.025993377483444 21
0.026158940397351 21
0.026324503311258 21
0.026490066225166 21
0.026655629139073 21
0.02682119205298 21
0.026986754966888 21
0.027152317880795 21
0.027317880794702 21
0.027483443708609 21
0.027649006622517 21
0.027814569536424 21
0.027980132450331 21
0.028145695364239 21
0.028311258278146 21
0.028476821192053 21
0.02864238410596 21
This MWE seems to be working but it prints a histogram instead lines:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
x_values y_frequency
0.000165562913907 20
0.000331125827815 20
0.000496688741722 20
0.000662251655629 20
0.000827814569536 20
\end{filecontents*}
\usepackage{pgfplots, pgfplotstable}
\usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.16}
% from https://tex.stackexchange.com/a/445369/121799
\newcommand*{\ReadOutElement}[4]{%
\pgfplotstablegetelem{#2}{#3}\of{#1}%
\let#4\pgfplotsretval
}
\begin{document}
\pgfplotstableread[header=true]{data.csv}\datatable
\pgfplotstablegetrowsof{\datatable}
\pgfmathtruncatemacro{\rownum}{\pgfplotsretval-1}
\foreach \X in {0,...,\rownum}
{\ReadOutElement{\datatable}{\X}{x_values}{\tmpx}
\ifnum\X=0
\xdef\lstSymbCoords{{\tmpx}}
\else
\xdef\lstSymbCoords{\lstSymbCoords,{\tmpx}}
\fi}
%\typeout{\lstSymbCoords}
\begin{tikzpicture}
\edef\temp{\noexpand\begin{axis}[
ybar,
ymin=0,
symbolic x coords={\lstSymbCoords},
xticklabel style={
rotate=90,
anchor=east}
]}
\temp
\addplot[
% hist={
% bins=7,
% data min=0.5,
% %data max=4
% }
] table [x=x_values,y=y_frequency] {\datatable};
\end{axis}
\end{tikzpicture}
\end{document}
ybar
makes a bar chart. I think your code is a lot more complicated than it needs be though, try removing all the\ReadOutElement
and\lstSymbCoords
stuff, and start with just\begin{tikzpicture} \begin{axis} \addplot table {data1.csv}; \addplot table {data2.csv}; \end{axis} \end{tikzpicture}
. Do you want to change the background colour as well? – Torbjørn T. May 31 '19 at 17:00matplotlib
already, you could try usingmatplotlib2tikz
to generate a file withpgfplots
code. – Torbjørn T. May 31 '19 at 17:23