Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to plot the solution of two inequalities and include them in a LaTeX paper. I really like they way this looks: Wolfram Alpha. Unfortunately, I have no idea how to export this into a LaTeX-suitable format and I don't have a version of Mathematica.

I have tried it with the implicitplot command of Maple but it does not look good at all. It displays the solutions of each of the inequalities but not both. Any ideas?

share|improve this question
3  
It is possible to do this without using Mathematica or Maple. That is, you can do this from within LaTeX. Are the inequalities in your link the ones you want plotted? –  Werner Dec 9 '11 at 23:25
1  
While Werners suggestion is better, and I'd recommend pursuing that, you can save a PDF from WolframAlpha (link towards the bottom) that will have a vectorized version of the plot. It's not a good solution though, as you have to crop the PDF somehow. –  Torbjørn T. Dec 10 '11 at 2:28
add comment

migrated from stackoverflow.com Dec 10 '11 at 1:35

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 19 down vote accepted

I would recommend that you plot these outside of Wolfram Alpha and just use LaTeX. Here is a pgfplots version that should get you started:

enter image description here

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}

    \begin{document}
    \begin{tikzpicture}
      \begin{axis}[
        thick,smooth,no markers,samples=100,
        ymin=-1.2,ymax=0.5,xmin=-1.5,xmax=1,
        xlabel=$x$, ylabel=$y$
        ]
            \addplot [domain=-1:0,fill=blue!20] {-sqrt(1-(x)^2)};
            \addplot [domain=-1:0]              {-x-1};
      \end{axis}
    \end{tikzpicture}
    \end{document}
share|improve this answer
    
If you interchange the \addplots, both border lines will have equal "thickness". –  Gonzalo Medina Dec 10 '11 at 2:35
    
@GonzaloMedina: Thanks, Have corrected the solution. I did notice that and was trying to figure how to correct it. Do you know why the order mattered in this case? –  Peter Grill Dec 10 '11 at 2:38
2  
As you had it, the straight line was drawn first and then the circular sector covered "half of it". Reversing the order, the sector is drawn first and then the line is not overwritten. Sorry I couldn't find a better way to say these in English; hope it makes sense ;-) –  Gonzalo Medina Dec 10 '11 at 2:42
add comment

The sagetex package is another option. Then you use Sage, which is free, instead of Mathematica or Maple.

\documentclass{article}
\usepackage{sagetex}
\begin{document}

\begin{sagesilent}
 var('x, y')
 P = region_plot([x+y+1<0,x^2+y^2-1<0], (x, -1, 1), (y, -1, 1), plot_points=300)
\end{sagesilent}

\sageplot[scale=.6]{P}

\end{document}

output

share|improve this answer
add comment

You mentioned having difficulty using Maple's implicitplot for this. You might well wish to use just latex packages such as pstricks or pgfplots, but here is a Maple code solution (tried in versions 13 and 15) since you mention that in both your post's title and body.

plots:-implicitplot( (x,y)->(y-(-sqrt(1-x^2)))*(y-(-x-1)),
                 -1..0,-1..0, view=[-1.5..1.5,-1.5..1.5],
                 gridrefine=3, filledregions=true, axes=boxed,
                 coloring=[COLOUR(RGB,.8,.8,.9),"white"],
                 labels=["x","y"] );

enter image description here

I zoomed in before exporting that image, which is why the axis labels look to small. If i hadn't panned in before exporting, those labels would be sized ok. (Sorry, first image insertion here.)

This post was imported from stackoverflow, where it had the maple tag, yes? Did that tag get lost, on import here? It may pr may not be the optimal solution, but the tag seems sensible as that software is mentioned in both title and text body.

share|improve this answer
    
Another way (which might possibly produce smoother curves) is to overlay a pair of filled implicit plots. The first colors in blue from first curve down to x-axis, while the second colors in white from second curve down to x-axis. with(plots): display( implicitplot( y<=-sqrt(1-x^2), x=-1..0, y=-1..0, filledregions=true, gridrefine=2, coloring=["white","white"] ), implicitplot( y<=-x-1, x=-1..0, y=-1..0, filledregions=true, coloring=[COLOUR(RGB,.8,.8,.9),"white"] ), axes=boxed, labels=["x","y"], view=-1.5..1.5,-1.5..1.5]); –  acer Dec 12 '11 at 10:31
add comment

Here's an option using PSTricks

screenshot

\documentclass{article}
\usepackage{pst-plot}

\begin{document}

\psset{algebraic=true,unit=3cm}

\begin{pspicture}(-1.5,-1.2)(1,0.6)
  \psaxes[dx=0.5,Dx=0.5,dy=0.5,Dy=0.5]{<->}(0,0)(-1.5,-1.2)(1,0.6)[$x$,0][$y$,90]
\pscustom[fillstyle=solid,fillcolor=blue,opacity=0.4]{%
\psplot{-1}{0}{-sqrt(1-x^2)}
\psplot{-1}{0}{-x-1}
}
\end{pspicture}
\end{document}

I hope I don't get flamed for doing this, but here's some Maple code that does the same thing

with(plots):
f:=x->-sqrt(1-x^2):     # define f(x)
g:=x->-x-1:         # define g(x)
a:=-1:  b:=0:       # interval [a,b]

# plotting window
xmin:=-2:   xmax:=2:    ymin:=-1:   ymax:=4:
N:=50:

# define the points for f(x) and g(x)
fpoints := [seq([a+(b-a)/N*i,f(a+(b-a)/N*i) ],i=0..N)]:
gpoints := Reverse([seq([a+(b-a)/N*i,g(a+(b-a)/N*i) ],i=0..N)]):

# plot them!
p1:=(polygon([
        seq(fpoints[i],i=1..N+1),
        seq(gpoints[i],i=1..N+1)
        ]), 
            color=red,
            gridlines=true,
            view = [xmin..xmax,ymin..ymax]):
p2:=plot(f(x),x=xmin..xmax):
p3:=plot(g(x),x=xmin..xmax):
display(p1,p2,p3);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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