I need to overlay two sns.catplots
One is of kind='box' and the other is kind='swarm' as follows:
gbox= sns.catplot( x="Emotion",y="Threshold",hue="Group", col = 'Task',
data=indata,palette ["skyblue","salmon"], kind="box", showmeans='True', meanline = 'True', height=6, aspect=0.8, boxprops={'facecolor':'None'}, edgecolor='gray')
sns.catplot( x="Emotion",y="Threshold",hue="Group", col = 'Task',
data=indata, palette=["skyblue","salmon"], kind="swarm",ax=gbox.axes)
I have tried taking the axes from one and feeding into the other catplot, but I receive an error as below. How can I fix this?
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-74-7a05cc88a396> in <module>
17
18 gbox =sns.catplot( x="Emotion",y="Threshold",hue="Group", col = 'Task',
---> 19 data=indata,palette=["skyblue","salmon"],kind="swarm",ax=gbox.axes)
20
21 #plt.show(gbox)
~/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in catplot(x, y, hue, data, row, col, col_wrap, estimator, ci, n_boot, units, order, hue_order, row_order, col_order, kind, height, aspect, orient, color, palette, legend, legend_out, sharex, sharey, margin_titles, facet_kws, **kwargs)
3753
3754 # Draw the plot onto the facets
-> 3755 g.map_dataframe(plot_func, x, y, hue, **plot_kws)
3756
3757 # Special case axis labels for a count type plot
~/anaconda3/lib/python3.6/site-packages/seaborn/axisgrid.py in map_dataframe(self, func, *args, **kwargs)
818
819 # Draw the plot
--> 820 self._facet_plot(func, ax, args, kwargs)
821
822 # Finalize the annotations and layout
~/anaconda3/lib/python3.6/site-packages/seaborn/axisgrid.py in _facet_plot(self, func, ax, plot_args, plot_kwargs)
836
837 # Draw the plot
--> 838 func(*plot_args, **plot_kwargs)
839
840 # Sort out the supporting information
~/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in swarmplot(x, y, hue, data, order, hue_order, dodge, orient, color, palette, size, edgecolor, linewidth, ax, **kwargs)
2989 linewidth=linewidth))
2990
-> 2991 plotter.plot(ax, kwargs)
2992 return ax
2993
~/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in plot(self, ax, kws)
1444 def plot(self, ax, kws):
1445 """Make the full plot."""
-> 1446 self.draw_swarmplot(ax, kws)
1447 self.add_legend_data(ax)
1448 self.annotate_axes(ax)
~/anaconda3/lib/python3.6/site-packages/seaborn/categorical.py in draw_swarmplot(self, ax, kws)
1374 # Set the categorical axes limits here for the swarm math
1375 if self.orient == "v":
-> 1376 ax.set_xlim(-.5, len(self.plot_data) - .5)
1377 else:
1378 ax.set_ylim(-.5, len(self.plot_data) - .5)
AttributeError: 'numpy.ndarray' object has no attribute 'set_xlim'
Thank you for your help!
SJ
In theory, using the .map and .map_dataframe methods should work, but
it fails when you do not want to use the same dimensionality across the plots that you are trying to overlay (for instance, using a different hue parameter for the first and second plot to show data split in different ways but overlaid)
EDIT it sort of works but only when sns.FacetGrid is first initiated independently with col/row argument, and the hue parameter is passed in individual .map_dataframe functions? I did not explore every combination, this is a bit hacky and inconsistently working in anyway.
it is impossible to control the zorder in which the two plots are overlaid (no matter in which order I call g.map(sns.pointplot, x, y1) and g.map(sns.pointplot, x, y2), the order between y1 and y2 will always be the same!!)
EDIT this is at least the case for pointplot, see issue #2339
Ideally, the catplot/lmplot/relplot/displot functions should allow a grid argument (equivalent to the ax argument of the other seaborn functions)!
You cannot pass an ax= parameter to catplot. You will need to create the FacetGrid "by hand".
Something like this: (untested because you did not provide data)
g = sns.FacetGrid(data=indata, hue="Group", col ='Task',
palette=["skyblue","salmon"])
g.map(sns.boxplot, x="Emotion", y="Threshold", showmeans='True', meanline = 'True',
height=6, aspect=0.8, boxprops={'facecolor':'None'}, edgecolor='gray')
g.map(sns.swarmplot, x="Emotion", y="Threshold")
Hi to whole stackoverflow group,
I am having a series of problems when defining the axes range in my graphic
and format in general, and I would like to share it with you to see if among all we can find the error
I have found on this website a user who has made it similar. My idea is to have something similar like the graphic of the link below. But for some reason, it's probably silly, it does not appear correctly.
My code is as following:
set term post eps enhanced color "Times-Roman" 14
set output "ComparacionPurezaMetodos.eps"
set key off
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.8
set xtic rotate by 90 scale 0
unset ytics
set y2tics rotate by 90
set y2label 'Ti_3SiC_2 content, wt{/Symbol\045}' offset -2.5
#set xlabel ' '
set size 0.6, 1
set label 'Powder mixture' at graph 0.5, -0.1 centre rotate by 180
plot 'datos.txt' using 1:(-1):3 with labels rotate right, 'datos.txt' using 1:2 with boxes
and the data are very simple:
# index, purity, name
1 98 Ti/Si/TiC
2 94 Ti/TiSi_2/TiC
3 93.6 Ti/Si/C
4 92 Ti/SiC/TiC
5 93 Ti/SiC/C
6 98 Ti/Si/C + Al
and I expect an output image like figure 4 (pag 6) of chapter 1 of this link:
https://books.google.es/books?id=zNWeBQAAQBAJ&printsec=frontcover&hl=es#v=onepage&q&f=false
But my output file does not have to do with this image.
Any idea / help?
Thanks in advance.
For your data, you don't need a histogram. Horizontal bars are sufficient. Instead of rotating a graph with plotting style with boxes you can use the plotting style with boxxyerror.
Make sure that your data separator is TAB or put your labels into "...".
### horizontal bars
reset session
set colorsequence classic
set datafile separator "\t"
$Data <<EOD
# index, purity, name
1 98 Ti/Si/TiC
2 94 Ti/TiSi_2/TiC
3 93.6 Ti/Si/C
4 92 Ti/SiC/TiC
5 93 Ti/SiC/C
6 98 Ti/Si/C + Al
EOD
unset key
set xlabel "Ti_2SiC_2 content, wt%" enhanced
set xrange [90:100]
set ylabel "Powder mixture"
unset ytics
set yrange [0:7]
set style fill solid 1.0
plot $Data u 2:1:(0):2:($1-0.4):($1+0.4):1 with boxxyerror lc variable,\
'' u 2:1:3 with labels offset 1,0 left
### end of code
Result:
I want to use imread function to load a .tif image in Octave-4.2.1, but there is an exception as follows:
Magick++ exception:
Magick:E:\CV\Digital image processing\img\a.tif:Null
count for "Tag 34026" (type 1, writecount -3, passcount 1). (_TIFFVSetField) reported by coders/tiff.c:793 (TIFFErrors) .
error: called from imread at line 80 column 10
imageIO at line 117 column 26
imread at line 106 column 30
but not all .tif images cannot be loaded, that's really weird
I converted a PNG image to hex and am wondering if it is possible to decompress the hex into this type of format for each pixel of the image:
Opacity(0-255)-Red(0-255)-Green(0-255)-Blue(0-255)
I'm using a site/program that has heavy restrictions on images you can upload(quality, size, amount, etc,) but I can create images pixel by pixel. I was hoping to decompress the hex that I converted from the original PNG file to the format above so that I can create a simple function to build it on the screen. Come to think of it, is there a way to pull the RGB and transparency from the hex PNG file without any need for reformatting?
It is very easy you have to cut your hexvalue,
and applicate an HEX to DECIMAL CONVERSION.
Ex : FFAACC00
FF = R = 255
AA = G = 170
CC = B = 204
00 = Transparency Full (FF = Transparency OFF)
If you need a program to do that you can use PNG2HEX.exe :
Download
(just drop your PNG File on it and it will create 2 files :
1- fileHex.txt with the value of each pixel in Hexa
2- FileRGB.txt with the value of each pixel in R G B
You can then modify values in these files and rebuild the png with the modification using
HEX2PNG.exe
I want to create a histogram of a file that contains :
1 144 12.54
2 564 02.34
3 231 01.23
4 452 07.12
and what I use for that purpose in my script is :
gnuplot << EOF
set terminal gif
set terminal postscript eps color enhanced
set output "diagramma";
set title 'Diagramma'
set key off
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.9
set autoscale
set xlabel "May"
plot 'finalsumfile' using 1:2 with histogram, 'finalsumfile' using 1:3 with histogram
EOF
So I want the first column as x coordinate and the second and third columns as y.
BUT when I run my script occurs this error:
line 0: Too many columns in using specification
What am I doing wrong?
try:
plot 'finalsumfile' using 2:xticlabels(1) with histogram
Histograms typically only take 1 column of data, which the "x-value" being implicitly incremented by one each time starting from 0. To set explicit x labels, you need to use xticlabels which takes the string in the given column and uses that as the label.