Gnuplot (or matplotlib): create a non-black chart with categories along the x axis

I would like to create such a graph using gnuplot (or matplotlib if necessary), but I don't know if / how to do this:

rough outline of what the graph should look like

This, of course, is just a rough sketch. The important thing is that I need to build pairs of values ​​(in this example, each pair consists of red and blue dots). One element from each pair is the only value, the other should show a range of values ​​(my idea was to display the average value with errors, to indicate the range of max and min, but I'm open to better ideas), the X axis has no purpose. besides specifying the names of the various categories - all that matters is the y values.

I am sure that I can create something like this (pairs of values ​​and x-categories) using histograms, but in this case the boxes will be simply erroneous.

What I have so far: I have this gnuplot command:

plot 'TEST.out' using 0:2:3:xticlabel(1) w errorbars pt 7 notitle 

Used with this data file (category name, y value, error string value):

 cat1 15 0 cat1 18 3 cat2 13 0 cat2 10 4 

it displays below a graph that goes in the right direction, but which is still not perfect (all data points have the same color, and for single values ​​you can still see that the error bars were used, and the grouping isn’t very nice - if the two points making up one pair were closer to each other, which would facilitate the graph on the eye).

where I have got so far

If anyone has suggestions (even to create a graph that doesn't look exactly the same as in the example I gave at the beginning). I will be very grateful.

Thanks so much for your time!

+4
source share
2 answers

In Matplotlib, you can set ticks individually. The method is explained in one example of Matplotlib .

Here is the start:

 # Initializations: from matplotlib import pyplot as pp import numpy as np pp.ion() # "Interactive mode on": pyplot.* commands draw immediately # Data: series_red_y = [1.3, 1.4, 2.2] series_blue_y = [1.6, 1.8, 1.8] series_blue_err = [0.25, 0.25, 0.5] names = ('Category 1', 'Category 2', 'Category 3') # Where on the x-axis the data will go: series_red_x = np.arange(0, 3*len(series_red_y), 3) # Step of 3: red dot, blue dot, empty space series_blue_x = np.arange(1, 3*len(series_blue_y)+1, 3) # Step of 3: red dot, blue dot, empty space # Plotting: pp.scatter(series_red_x, series_red_y, c='r', s=100) pp.scatter(series_blue_x, series_blue_y, s=100) pp.errorbar(series_blue_x, series_blue_y, yerr=series_blue_err, fmt=None, capsize=0) pp.xticks((series_red_x+series_blue_x)/2., names) # We wait until the user is ready to close the program: raw_input('Press enter...') 

Here is the result you can customize for your specific needs:

enter image description here

+5
source

Here is the gnuplot solution:

 set xrange [-.25:2.75] set xtics ('cat0' .25, 'cat1' 1.25, 'cat2' 2.25) plot '< sed 1~2!d TEST.out' using 0:2:(.1) with circles, \ '< sed 1~2d TEST.out' using (.5+$0):2:3 with errorbars 

You may need to generate the first two lines of the script if the number of categories is not known in advance. It should be pretty easy, for example. in bash:

 cat_count=$(wc -l < TEST.out) let cat_count/=2 let cat_count-- echo xrange "[-.25:$cat_count.75]" echo -n 'set xtics(' for i in $(seq 0 $cat_count) ; do echo -n "'cat$i'" $i.25 ((i==cat_count)) || echo -n , done echo ')' 
+1
source

Source: https://habr.com/ru/post/1384521/


All Articles