0

I tried to plot my data using some packages but I didn't get something nice. I've data like this:

X=[590 598 599 600 601 602 603 604 605 606 607 608 609 610 611 627 628 629 634 641 642 644 645 648 649 651 652 653 654 655 657 658 659 660 690 691 692 693 694 695 696 697 698 699 700 701 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 720 721 722 723 724 726 729 730 731 732 733 734 735 736 737 738 739 740 741 744 761 762 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 800 801 802 803 804 806 807 808 809 810 812 813 814 816 818 819 820 821 822 824 825 827 828 830 831 833 835 837 838 839 841 843 860 875 876 877 879 881 884 885 886 889 910 926 927 928 929 930 932 933 934 935 936 937 938 939 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 959 997 999 1000];

Y=[2 6 4 4 3 5 5 3 6 2 3 5 2 3 3 1 1 -1 1 -1 -1 -1 -2 1 1 -2 -1 -1 -1 -1 -2 -3 2 -2 1 1 -1 -1 2 3 1 2 2 2 -1 -1 -1 2 -1 5 6 3 1 1 3 5 1 4 2 3 1 4 1 3 2 1 -2 -1 1 7 2 1 6 2 2 1 5 -1 6 4 3 1 2 2 7 6 8 7 3 -1 3 5 5 9 2 2 1 4 1 4 6 1 -1 5 3 3 3 1 2 3 1 -2 5 10 6 2 6 7 4 2 5 4 2 5 3 1 6 6 2 3 3 2 1 3 2 1 3 2 2 2 -2 -2 -1 1 1 1 1 1 1 -1 -1 1 1 3 -1 9 -3 -2 -2 -1 1 1 1 -1 1 2 5 1 -1 4 1 4 1 -1 4 1 2 -1 1 1 7 1 3 5 4 3 1 2 1 3 3 2 1 1]

I want to show that I've more positive numbers in Y than negative ones. X are just frame numbers (images).

I get something like that using tikzpicture enter image description here

Someone has any better idea how to plot those data?

  • May be a histogram would be a better option... – koleygr Aug 15 '17 at 13:59
  • 1
    Or just use \addplot[only marks, ... so that you get rid of the lines. – Thruston Aug 15 '17 at 14:00
  • @koleygr A histogram will look like just two horizontal lines of positive and negative values.. that what you mean? – ROS_Latex Aug 15 '17 at 14:07
  • @ROS_Latex You can choose what it will show... you can show every number (from -3 to 10) in x axis or families (by 3 or whatever). Y axis will show how many points have this value or are in this area of values – koleygr Aug 15 '17 at 14:09
  • If you will do @Thruston's suggestion don't forget to remove x labels – koleygr Aug 15 '17 at 14:11
4

Put your data into a table and place markers depending on the sign of the data

\documentclass[]{article} 
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.14}

\pgfplotstableread{
X Y
         590           2
         598           6
         599           4
         600           4
         601           3
         602           5
         603           5
         604           3
         605           6
         606           2
         607           3
         608           5
         609           2
         610           3
         611           3
         627           1
         628           1
         629          -1
         634           1
         641          -1
         642          -1
         644          -1
         645          -2
         648           1
         649           1
         651          -2
         652          -1
         653          -1
         654          -1
         655          -1
         657          -2
         658          -3
         659           2
         660          -2
         690           1
         691           1
         692          -1
         693          -1
         694           2
         695           3
         696           1
         697           2
         698           2
         699           2
         700          -1
         701          -1
         703          -1
         704           2
         705          -1
         706           5
         707           6
         708           3
         709           1
         710           1
         711           3
         712           5
         713           1
         714           4
         715           2
         716           3
         717           1
         718           4
         720           1
         721           3
         722           2
         723           1
         724          -2
         726          -1
         729           1
         730           7
         731           2
         732           1
         733           6
         734           2
         735           2
         736           1
         737           5
         738          -1
         739           6
         740           4
         741           3
         744           1
         761           2
         762           2
         764           7
         765           6
         766           8
         767           7
         768           3
         769          -1
         770           3
         771           5
         772           5
         773           9
         774           2
         775           2
         776           1
         777           4
         778           1
         780           4
         781           6
         782           1
         783          -1
         784           5
         785           3
         786           3
         787           3
         788           1
         789           2
         790           3
         791           1
         792          -2
         793           5
         794          10
         795           6
         796           2
         797           6
         798           7
         800           4
         801           2
         802           5
         803           4
         804           2
         806           5
         807           3
         808           1
         809           6
         810           6
         812           2
         813           3
         814           3
         816           2
         818           1
         819           3
         820           2
         821           1
         822           3
         824           2
         825           2
         827           2
         828          -2
         830          -2
         831          -1
         833           1
         835           1
         837           1
         838           1
         839           1
         841           1
         843          -1
         860          -1
         875           1
         876           1
         877           3
         879          -1
         881           9
         884          -3
         885          -2
         886          -2
         889          -1
         910           1
         926           1
         927           1
         928          -1
         929           1
         930           2
         932           5
         933           1
         934          -1
         935           4
         936           1
         937           4
         938           1
         939          -1
         941           4
         942           1
         943           2
         944          -1
         945           1
         946           1
         947           7
         948           1
         949           3
         950           5
         951           4
         952           3
         953           1
         954           2
         955           1
         956           3
         959           3
         997           2
         999           1
        1000           1
}\mytable

\begin{document}
\begin{tikzpicture}
\begin{axis}[ytick=0,xtick=\empty, ymajorgrids, hide x axis, axis y line*=left]
\addplot[scatter, only marks, point meta=sign(y)] table \mytable;
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • It is important to note that a graph or diagramn should only depict relevant data. With the author saying "X are just frame numbers (images)" he is saying those are irrelevant and so they should not be shown in the graph. This picture proofs this, because its just a random distribution of dots on the x-axis. – JulianWgs Aug 16 '17 at 5:51
  • @Julian_W you're right! that's not a very useful information – ROS_Latex Aug 16 '17 at 7:24
3

enter image description here

Why dont you use a histogram as suggested? This was made in Matlab, but can be easily replicated in LaTex. I think this shows the distribution best.

It is important to note that a graph or diagramn should only depict relevant data. With you saying "X are just frame numbers (images)" you are admitting those are irrelevant and so they should not be shown in the graph.

Edit: This is how its done in LaTex/Pgfplots. Part of the code was taken from How to compute an histogram (plot bars) binning the values from a .csv using TeX?. Note that Matlab and pgfplots use different ranges to calculate the histogram. I still prefer the one in Matlab and I would suggest using Matlab to work with the data and then just display it with a bar graph in LaTex. A free alternative is Octave by the way.

To convert the data I used the replace function in Notepad++ (replace " " with \n).

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots, pgfplotstable}
\usepgfplotslibrary{statistics}

\begin{filecontents}{data}
2
6
4
4
3
5
5
3
6
2
3
5
2
3
3
1
1
-1
1
-1
-1
-1
-2
1
1
-2
-1
-1
-1
-1
-2
-3
2
-2
1
1
-1
-1
2
3
1
2
2
2
-1
-1
-1
2
-1
5
6
3
1
1
3
5
1
4
2
3
1
4
1
3
2
1
-2
-1
1
7
2
1
6
2
2
1
5
-1
6
4
3
1
2
2
7
6
8
7
3
-1
3
5
5
9
2
2
1
4
1
4
6
1
-1
5
3
3
3
1
2
3
1
-2
5
10
6
2
6
7
4
2
5
4
2
5
3
1
6
6
2
3
3
2
1
3
2
1
3
2
2
2
-2
-2
-1
1
1
1
1
1
1
-1
-1
1
1
3
-1
9
-3
-2
-2
-1
1
1
1
-1
1
2
5
1
-1
4
1
4
1
-1
4
1
2
-1
1
1
7
1
3
5
4
3
1
2
1
3
3
2
1
1
\end{filecontents}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    ymin=0
]
\addplot +[
    hist={
        bins=13 %this says how many columns you want (10-(-3)=13)
    }   
] table [y index=0] {data};
\end{axis}
\end{tikzpicture}
\end{document}
| improve this answer | |
  • Can you please show us how we can plot this histogram using TeX-and-friends tools, for example using the PGFplots pgfplots/hist key, from the statistics library ? – marsupilam Aug 15 '17 at 20:56
  • come to the dark side and switch to Python instead. matlab plots are horrible anyways. – percusse Aug 16 '17 at 7:23
  • I was working on histogram version after it gets suggested. I would plot it on Matlab too, it's more easier. Thanks for the solution. – ROS_Latex Aug 16 '17 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.