Is there a way to define an alpha channel in a palette in either gnuplot or matplotlib?
I'm trying to combine two scalar fields into one plot and so far came up with nothing.
There is a way to set line colors with an alpha channel in the development version (4.7) of gnuplot. You can set the alpha channel as the high bits of an RGB color specification. For example,
plot x lc rgb '#AAAAAAAA'
draws a translucent gray line.
However, I'm not sure there is a way to do this for a palette.
Related
Is it possible to change the opacity of the key's background in gnuplot? I can only find the option to toggle between opaque or transparent.
Here is an example using python's matplotlib - https://matplotlib.org/3.2.0/_images/dflt_style_changes-14.png
This is possible in the development version (5.5) and in the most recent release version (5.4.2) but not in earlier versions.
set key box opaque fillcolor "0x7faaaaaa"
There is a cumbersome workaround for filling the key box with a custom color:
Set custom background color for key in Gnuplot.
However, it seems like semi-transparent colors are not accepted as terminal background.
Well, either you want to see the data and place the legend next to it
or you cover the data with the legend, then the data is not "important".
Putting a semi-transparent legend box on top of data seems to me a bit of a strange mix of both.
The only workaround I see currently is to manually place a semi-transparent box on top of the plot and behind the legend.
The only way I succeeded so far to get this into the right layer stacking order is to plot a box with boxxyerror and add the legend via keyentry. You can put the coordinates and size of the box e.g. into the datablock $myBox. A pretty ugly workaround, but I'm happy to learn about better solutions.
Code:
### manual workaround for semi-transparent fill of key box
reset session
set style fill solid 1.0
set key center at 0,-0 noautotitle box
$myBox <<EOD
0 -0 1.25 1.25
EOD
plot x w filledcurves x1 lc rgb 0xccff0000, \
-x w filledcurves x1 lc rgb 0xcc0000ff, \
$myBox u 1:2:3:4 w boxxy lc rgb 0x77ffffff noautoscale, \
keyentry w filledcurves x1 lc rgb 0xccff0000 ti "x" , \
keyentry w filledcurves x1 lc rgb 0xcc0000ff ti "-x"
### end of code
Result: (wxt terminal)
I have a pie chart and I would like to put a legend with the same colors in the cells.
The Pie chart has a transparency of 22.5%.
If I use the same RGB combination when I set the color in the cell, this color is different because it is much darker.
'___COLORS FOR LEGEND PIE____
If inc < 14 Then ws.Cells(rx + inc, 19).Interior.Color = RGB(colorR, colorG, colorB)
Is there a way to set transparency? I know it is possible in the charts.
If there is no way to set transparency, how canm I change my RGB code to adapt to a transparency of 22.5%?
The answer is you can't set the transparency of a cell in Excel.
This is because the Range.Interior.Color only supports the RGB and not RGBA. A - stands for ALPHA which is used for transparency.
One way around it (which I wouldn't recommend) would be to insert a shape (say a rectangle) over the cell and set its transparency to match the already transparent chart but if you have a lot of data this will definitely slow things down and if your data chages often or you are inserting/removing rows this will just be a real pain in the back bone.
Another idea would be to go online and find 2 sets of colors RGBA and its somehow matching RGB equivalents. I have seen such solutions before but never tried it myself so I can't give you any tips on it.
I'm using gnuplot to generate the following surface plot.
The important part of the command file I'm using is:
set terminal pdfcairo size 3,3;
In particular the size 3,3 resizes the plot to the way I want but crops out part of the z-axis label in the process. If I use a wider size like size 4,3 or don't use the size option at all then the z-axis labels fit as follows:
It seems that gnuplot doesn't take the width of the label into consideration when resizing the plot.
Is there a way to maybe move the plot to the right before resizing to 3,3 so that there's room to scientific notation?
You can set the lmargin option:
set lmargin 10
(or whatever size doesn't crop the label).
I need to display data from a 2D matrix in a gray colormap, but I need to define it in such a gray scale that white and black are not the colors for the min and max values of the matrix, in order to not saturate the image. What I need is a gray scale colormap with gray levels between 20% and 70%, with at least 20% difference between the levels of gray. Any suggestions?
I'm using the imshow task form matplotlib.
Thanks a lot!
Did you solve your problem?
I guess this is what you want, try this:
all code in pylab mode:
a = np.arange(100).reshape(10,10)
#here is the image with white and black end
imshow(a,cmap=mat.cm.binary)
colorbar()
#we extract only the 0.2-->0.7 part of original colormap and make a new one
#so that the white and black end are removed
rgba_array = mat.cm.binary(np.linspace(0,1,num=10,endpoint=True))
extract_rgba_array_255 = rgba_array[2:8,0:3]
imshow(a,cmap=mat.colors.ListedColormap(extract_rgba_array_255))
colorbar()
You could do this either by creating a custom color map with colors your prefer, or by using the vmin, vmax keywords in imshow to force a larger range on the colorbar than you want to use in your plot.
I'm struggling with a problem when making plots with filledcurves. Between the filled areas, there seems to be a "gap". However, these artifacts do not appear on the print, but depend on the viewer and zoom-options. In Gnuplot I use the eps terminal, the eps-files look great, but the lines appear when I'm converting to pdf. The conversion it either done directly after plotting or when converting the latex-document from dvi to pdf. As most of the documents are here on the display nowadays, this is an issue. The problem also appears when I'm directly using the pdfcairo terminal in Gnuplot, so it's not caused by the conversion (tried epstopdf and ps2pdf) alone.
I attached a SCREENSHOT of a plot displayed in "acroread" (same problem in other pdf-viewers).
Has anybody an idea how to get rid of it but keeping the graphic vectorized?
I just ran into the same issue. Apparently the filling between two curves
is done as a set of polygons that do not exactly touch one another, thus
the thin white lines visible on some PDF viewers.
One way to fix the issue is to draw over these polygon boundaries. First
define min and max functions in gnuplot:
min(x, y) = x < y ? x : y
max(x, y) = x > y ? x : y
Then, assuming that column 1 of "datafile" contains your x values and
that columns 2 and 3 contain the y values of curves 2 and 3, write:
plot "datafile" using 1:2:3 with filledcurves lc rgb "gray", \
"" using 1:2:(min($2, $3)):(max($2, $3)) with yerrorbars ps 0 lt 1 \
lc rgb "gray" lw 0.5
The first plot instruction fills the spaces between the curves in gray.
The second plot instruction draws points of zero size (ps 0) at each
x value (1) on curve (2) with thin (lw 0.5), continuous (lt 1), gray
(lc rgb "gray"), vertical errorbars (yerrorbars) from the lower to
the higher of curves 2 and 3.
This covers the white lines. To get best results you may need to
experiment with the thickness of the bars (e.g., lw 0.6, lw 0.2).
This issue is fixed with gnuplot 5.2, see https://sourceforge.net/p/gnuplot/patches/749/
The actual problem was, that filled curves were previously plotted as many quadrilaterals, which leads to artifacts (white stripes) in many viewers due to antialiasing.
Since version 5.2 filled curves are rendered as single polygon, which prevents these problems (see issue linked above).
The problem is still present in Gnuplot 5.0.4 and at least the cairolatex terminal which I use to output PDFs.
I also wanted to color the area between two curves, in my case defined as functions.
When I used something like
f(x) = 2 + sin(x)
g(x) = cos(x)
plot '+' using 1:(f($1)):(g($1)) with filledcurves closed
I got the same vertical white lines as in the question.
A simple solution for curves where one is always above the other is to let Gnuplot fill the area from the upper curve to the x-axis with the desired color and then paint it over with white from the lower curve downwards:
f(x) = 2 + sin(x)
g(x) = cos(x)
plot f(x) with filledcurves x1, g(x) w filledc x1 fs lc rgb "white"
Apparently this filledcurves style (not between curves but between a curve and an axis) avoids the trapezoid artifacts.
This can be readily extended for plotting data files and multiple stacked cures like in the question. Just paint from top to bottom and finish with white for the empty area between the lowest curve and the x-axis.
For overlapping curves a construction of minimum and maximum curves like in the answer from françois-tonneau might do the trick.
If you're talking about the red and cyan bits the gap could be an illusion caused by the Red + Cyan = White on a RGB screen. Maybe there's no gap, but the border areas appear as white due to the proximity of the pixels.
Take the screenshot and blow it up so you can see the individual pixels around the perceived gap.
If this is the case, maybe selecting a different colour scheme for the adjacent colurs would get rid of the effect. I certainly can't see anything matching your description on anywhere but the red and cyan bits.
From https://groups.google.com/forum/#!topic/comp.graphics.apps.gnuplot/ivRaKpu5cJ8, it seemed to be a pure Gostscript issue.
Using the eps terminal of Gnuplot and converting the eps file to pdf with
epstopdf -nogs <file.eps> -o <file.pdf>
solved the problem on my system. From the corresponding Man page, the "-nogs" option instructs epstopdf not to use Gostscript.