Graphics, Figures & TablesPSTricks | Problem with transparent Filling

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
niles
Posts: 92
Joined: Mon Dec 01, 2008 9:35 pm

PSTricks | Problem with transparent Filling

Post by niles »

Hi

I have the following graph written in PSTricks (I apologize for the length, but it was the most simple example I could think of):

Code: Select all

\documentclass{article}
\usepackage{pstricks, pst-node, pst-plot, pst-circ}
\usepackage{moredefs}
\usepackage[%
    paperwidth = 10.67523cm, % add 0.5%
    paperheight= 8.5754881cm, % add 0.5%
    lmargin    = -5.25mm, % do not know why this offset is needed.
    rmargin    = 0mm, %
    tmargin    = 0mm, %
    bmargin    = 0mm, %
    ]{geometry}
\begin{document}

% Global Parameters that can be changed:
\providelength{\AxesLineWidth}       \setlength{\AxesLineWidth}{0.5pt}%
\providelength{\GridLineWidth}       \setlength{\GridLineWidth}{0.4pt}%
\providelength{\GridLineDotSep}      \setlength{\GridLineDotSep}{0.4pt}%
\providelength{\MinorGridLineWidth}  \setlength{\MinorGridLineWidth}{0.4pt}%
\providelength{\MinorGridLineDotSep} \setlength{\MinorGridLineDotSep}{0.8pt}%
\providelength{\plotwidth}           \setlength{\plotwidth}{10cm}% width of the axes only
\providelength{\LineWidth}           \setlength{\LineWidth}{0.7pt}%
\providelength{\EdgeLineWidth}       \setlength{\EdgeLineWidth}{0.4pt}%
\providelength{\MarkerSize}          \setlength{\MarkerSize}{4pt}%
\newrgbcolor{GridColor}{0.8 0.8 0.8}%
%
% Begin Figure:-------------------------------------------
\psset{xunit=0.142857\plotwidth,yunit=0.197177\plotwidth}%
\begin{pspicture}(-0.354839,-0.233918)(7.080645,4.093567)%

% Draw bounding box for test aspects: ----
% \psframe(-0.354839,-0.233918)(7.080645,4.093567)
% Total width:  10.622120 cm
% Total height: 8.532824 cm

% Draw Grid: ----
% x-Grid:
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,0.000000)(0.000000,4.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](1.000000,0.000000)(1.000000,4.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](2.000000,0.000000)(2.000000,4.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](3.000000,0.000000)(3.000000,4.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](4.000000,0.000000)(4.000000,4.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](5.000000,0.000000)(5.000000,4.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](6.000000,0.000000)(6.000000,4.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](7.000000,0.000000)(7.000000,4.000000)
% y-Grid:
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,0.000000)(7.000000,0.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,0.500000)(7.000000,0.500000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,1.000000)(7.000000,1.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,1.500000)(7.000000,1.500000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,2.000000)(7.000000,2.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,2.500000)(7.000000,2.500000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,3.000000)(7.000000,3.000000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,3.500000)(7.000000,3.500000)
\psline[linestyle=dashed,dash=2pt 3pt,dotsep=\GridLineDotSep,linewidth=\GridLineWidth,linecolor=GridColor](0.000000,4.000000)(7.000000,4.000000)

% Draw Ticks: ----
% x-Ticks:
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,0.000000)(0.000000,0.060859)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](1.000000,0.000000)(1.000000,0.060859)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](2.000000,0.000000)(2.000000,0.060859)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](3.000000,0.000000)(3.000000,0.060859)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](4.000000,0.000000)(4.000000,0.060859)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](5.000000,0.000000)(5.000000,0.060859)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](6.000000,0.000000)(6.000000,0.060859)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](7.000000,0.000000)(7.000000,0.060859)
% y-Ticks:
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,0.000000)(0.084000,0.000000)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,0.500000)(0.084000,0.500000)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,1.000000)(0.084000,1.000000)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,1.500000)(0.084000,1.500000)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,2.000000)(0.084000,2.000000)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,2.500000)(0.084000,2.500000)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,3.000000)(0.084000,3.000000)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,3.500000)(0.084000,3.500000)
\psline[linewidth=\AxesLineWidth,linecolor=GridColor](0.000000,4.000000)(0.084000,4.000000)

{ \footnotesize % FontSizeTickLabels
% Draw x-Labels: ----
\rput[t](0.000000,-0.060859){$0$}
\rput[t](1.000000,-0.060859){$1$}
\rput[t](2.000000,-0.060859){$2$}
\rput[t](3.000000,-0.060859){$3$}
\rput[t](4.000000,-0.060859){$4$}
\rput[t](5.000000,-0.060859){$5$}
\rput[t](6.000000,-0.060859){$6$}
\rput[t](7.000000,-0.060859){$7$}
% Draw y-Labels: ----
\rput[r](-0.084000,0.000000){$0$}
\rput[r](-0.084000,0.500000){$0.5$}
\rput[r](-0.084000,1.000000){$1$}
\rput[r](-0.084000,1.500000){$1.5$}
\rput[r](-0.084000,2.000000){$2$}
\rput[r](-0.084000,2.500000){$2.5$}
\rput[r](-0.084000,3.000000){$3$}
\rput[r](-0.084000,3.500000){$3.5$}
\rput[r](-0.084000,4.000000){$4$}
} % End FontSizeTickLabels

% Draw Axes: ----
\psframe[linewidth=\AxesLineWidth,dimen=middle](0.000000,0.000000)(7.000000,4.000000)

{ \small % FontSizeXYlabel
} % End FontSizeXYlabel

% New Patch DATA: ----
\newrgbcolor{Lcolor181.0161}{0  0  0}
\newrgbcolor{Fcolor181.0161}{0.4           0      0}
\savedata{\mydata}[{
{1.884956,3.553058},{1.994391,4.000000},{6.283185,4.000000},{6.283185,0.000000},{0.000000,0.000000},
{0.314159,0.098696},{0.628319,0.394784},{0.942478,0.888264},{1.256637,1.579137},{1.570796,2.467401},
{1.884956,3.553058}
}]
\dataplot[fillstyle=solid,fillcolor=Fcolor181.0161,plotstyle=line,linestyle=solid,linewidth=\EdgeLineWidth,linecolor=Lcolor181.0161]{\mydata}

\end{pspicture}%

\end{document}
I want the red part to be "transparently" red, I think they call it alpha channel (?). I tried changing "fillstyle=transparent", but that could not compile.

Thanks for the help in advance.

Best,
Niles.
Attachments
graph.tex
(6.91 KiB) Downloaded 262 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Problem with transparent Filling

Post by CrazyHorse »

use

Code: Select all

\dataplot[fillstyle=solid,fillcolor=Fcolor181.0161,
      plotstyle=line,
  
      linestyle=solid,linewidth=\EdgeLineWidth,
      linecolor=Lcolor181.0161,opacity=0.4]{\mydata}

opacity is the optional argument for transparency
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

PSTricks | Problem with transparent Filling

Post by localghost »

niles wrote:[…] I have the following graph written in PSTricks […]
Seems to me more like the result of an export from another software.
niles wrote:[…](I apologize for the length, but it was the most simple example I could think of) […]
Could probably be done a bit shorter (and easier).

Code: Select all

\documentclass{article}
\usepackage{pst-plot,pstricks-add}

\newrgbcolor{Lcolor181.0161}{0 0 0}
\newrgbcolor{Fcolor181.0161}{0.4 0 0}

\begin{document}
  \psset{
    llx=-1cm,
    lly=-1cm,
    xAxisLabel={x axis},
    xAxisLabelPos={c,-0.55cm},
    yAxisLabel={y axis},
    yAxisLabelPos={-1cm,c}
}
  \begin{psgraph}[
    axesstyle=frame,
    Dy=.5,
    xticksize=0 4,
    yticksize=0 7,
    ticklinestyle=dotted,
  ](0,0)(7,4){10cm}{7cm}
    \savedata{\mydata}[{
      {0.000000,0.000000},
      {0.314159,0.098696},
      {0.628319,0.394784},
      {0.942478,0.888264},
      {1.256637,1.579137},
      {1.570796,2.467401},
      {1.884956,3.553058},
      {1.994391,4.000000}
    }]
    \pscustom[
      linestyle=none,
      fillstyle=solid,
      opacity=0.25,
      fillcolor=Fcolor181.0161,
    ]{
      \dataplot[
        plotstyle=curve,
        linestyle=solid,
        linecolor=Lcolor181.0161
      ]{\mydata}
      \psline(1.994391,4)(6.3,4)(6.3,0)
    }
  \end{psgraph}
\end{document}
Needs "LaTeX → PS → PDF" or XeLaTeX. The option for opacity has already been mentioned.


Thorsten
Attachments
The obtained output.
The obtained output.
pstricks-graph.png (12.18 KiB) Viewed 5101 times
niles
Posts: 92
Joined: Mon Dec 01, 2008 9:35 pm

PSTricks | Problem with transparent Filling

Post by niles »

Thanks to both of you. It works! I actually tried it out myself, but then it didn't work. But I was running MikTeX 2.8, so that was why -- now I have updated to 2.9, and everything is good now.


localghost wrote:
niles wrote:[…] I have the following graph written in PSTricks […]
Seems to me more like the result of an export from another software.
That is true - it is from fig2tex (but that is also why I didn't say that I had written it myself, I only said it was written in PSTricks). Thanks for the quick help.

Best,
Niles.
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Problem with transparent Filling

Post by CrazyHorse »

niles wrote:Thanks to both of you. It works! I actually tried it out myself, but then it didn't work. But I was running MikTeX 2.8, so that was why -- now I have updated to 2.9, and everything is good now.
If you want only the dashed coordinate lines visible, then you can use another optional argument to draw these lines at the end. Then they are always on top of each other objects.
Post Reply