2
$\begingroup$

How would I plot the PDF (probability density function) of WeibullDistribution[1/5, 50], WeibullDistribution[1/4, 40], WeibullDistribution[1/3, 30] and WeibullDistribution[1/2, 20] in the same graph?

$\endgroup$
  • 4
    $\begingroup$ There are good examples how to do this in the documentation of the {WeibullDistribution} $\endgroup$ – Matariki May 1 '12 at 0:51
8
$\begingroup$

Here is a simple way. The Evaluate is needed to ensure the line colors are different (see this question for an explanation of this).

Plot[Evaluate[
  PDF[WeibullDistribution[1/#, 10 #], x] & /@ Range[2, 5]], {x, 0.1, 5}]

enter image description here

As noted in the documentation, Plot and related functions quite happily draw multiple lines if they are given a list of functions (or data in the case of ListPlot and friends) as their first argument.

Notice the use of Map (/@) and a pure function to avoid having to type out the WeibullDistribution bit of the code multiple times. (This page in the documentation will be useful in this regard.)

$\endgroup$
  • $\begingroup$ Thank you for the link to the Map documentation, that is very useful! In this case you used "#" for both parameters. But, let's say I would want to map 1 list of values to the first parameter, and one to the second parameter, how would I do this? $\endgroup$ – Chris May 1 '12 at 1:05
  • $\begingroup$ @Chris You should look up Apply (@@) and apply at level 1 (@@@). A simple example which you can extend to your case is the following: Clear[f];f[#1, #2] & @@@ Transpose[{Range[5], Range[6, 10]}] $\endgroup$ – rm -rf May 1 '12 at 1:10
  • $\begingroup$ @Chris: Also have a look at MapThread. But this is really a separate question. $\endgroup$ – Verbeia May 1 '12 at 1:11
4
$\begingroup$

Another way to write Verbeia's code:

Plot[#, {x, 0.1, 5}] & @
  Array[PDF[WeibullDistribution[1/#, 10 #], x] &, 4, 2]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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