Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bar chart style with ListPlot

1,058 views
Skip to first unread message

Michael A. Gilchrist

unread,
Jun 19, 2010, 7:50:41 AM6/19/10
to
Hello,

I'm working with some discrete probability functions and plotting them using
ListPlot. Given the nature of the function, I believe its clearest to
represent the values using bars rather than points. I know there's a BarChart
function, but it isn't as easy to use (e.g. you can't just give it a list of
x, y coordinates and you can't easily have overlaying datasets, they sit next
to each other).

I'm wondering if anyone else has run into this problem and/or has any
suggestions on how to solve it. For example, are there options I can set that
will give me the desired behavior?

Thanks for your time in this matter,

Sincerely,

Mike

Sjoerd C. de Vries

unread,
Jun 20, 2010, 3:44:16 AM6/20/10
to
Michael,

How about this:

ListPlot[Prime[Range[25]], Filling -> Axis,
FillingStyle -> {Thickness[0.03]}, ImageSize -> 500, Axes -> None,
Frame -> True]

Not a beauty, but it does what you ask for.

Cheers -- Sjoerd

Bill Rowe

unread,
Jun 20, 2010, 3:44:51 AM6/20/10
to
On 6/19/10 at 7:46 AM, mi...@utk.edu (Michael A. Gilchrist) wrote:

>I'm working with some discrete probability functions and plotting
>them using ListPlot. Given the nature of the function, I believe
>its clearest to represent the values using bars rather than
>points. I know there's a BarChart function, but it isn't as
>easy to use
>(e.g. you can't just give it a list of x, y coordinates and you
>can't easily have overlaying datasets, they sit next to each other).

>I'm wondering if anyone else has run into this problem and/or has
>any suggestions on how to solve it. For example, are there options
>I can set that will give me the desired behavior?

Instead of BarChart, I would use either DiscretePlot (when the
distribution can be specified as a function) or ListPlot. For
example, with DiscretePlot

DiscretePlot[{PDF[BinomialDistribution[50, .8], k],
PDF[BinomialDistribution[50, .3], k]}, {k, 0, 50}, Frame -> True]

or with ListPlot

ListPlot[{Table[PDF[BinomialDistribution[50, .8], k], {k, 0, 50}],
Table[PDF[BinomialDistribution[50, .3], k], {k, 0, 50}]},
PlotStyle -> PointSize[.015], Filling -> Axis,
FillingStyle -> Thickness[.002], Frame -> True]


Michael A. Gilchrist

unread,
Jun 20, 2010, 3:45:13 AM6/20/10
to
Hi Michael,

Thanks to you and the others who've responed. That was almost exactly the
type of solution I was looking for.

I'm left with one question and that is, "How do I get the colors to
automatically parallel the colors being used for the symbols?" I suspect one
can do this with a function command embedded within the FillingStyle-> option,
but I've always found the syntax for such things trick.

Thanks again for pointing out this simple solution and any help with this
latter request would be appreciated.

Best,

Mike

On Sat, 19 Jun 2010, Michael Stern wrote:

> For a project on which I am currently working, I am using ListPlot[] (actually DateListPlot[]) with Filling towards the axis. I am not sure what effect you are trying to achieve, but you may find this technique useful. The particular options on which I am relying are Filling -> Axis, FillingStyle -> {{Red, AbsoluteThickness[5]}, {Black, AbsoluteThickness[10]}}, which creates the appearance of a bar chart where bars above the axis are thicker and black, bars below the axis are thinner and red.
>
> Good luck,
>
> Michael Stern
> Merrin Capital Management
>
>
> On Jun 19, 2010, at 7:46 AM, Michael A. Gilchrist wrote:
>
>> Hello,


>>
>> I'm working with some discrete probability functions and plotting them using
>> ListPlot. Given the nature of the function, I believe its clearest to
>> represent the values using bars rather than points. I know there's a BarChart
>> function, but it isn't as easy to use (e.g. you can't just give it a list of
>> x, y coordinates and you can't easily have overlaying datasets, they sit next
>> to each other).
>>
>> I'm wondering if anyone else has run into this problem and/or has any
>> suggestions on how to solve it. For example, are there options I can set that
>> will give me the desired behavior?
>>

Bob Hanlon

unread,
Jun 20, 2010, 3:47:54 AM6/20/10
to

ListPlot[
Table[
{k,
PDF[BinomialDistribution[50, 0.3], k]},
{k, 0, 30}],
Filling -> Axis,
FillingStyle -> Thick]


Bob Hanlon

---- "Michael A. Gilchrist" <mi...@utk.edu> wrote:

=============

Michael Stern

unread,
Jun 20, 2010, 3:56:35 AM6/20/10
to
For a project on which I am currently working, I am using ListPlot[] (actually DateListPlot[]) with Filling towards the axis. I am not sure what effect you are trying to achieve, but you may find this technique useful. The particular options on which I am relying are Filling -> Axis, FillingStyle -> {{Red, AbsoluteThickness[5]}, {Black, AbsoluteThickness[10]}}, which creates the appearance of a bar chart where bars above the axis are thicker and black, bars below the axis are thinner and red.

Good luck,

Michael Stern
Merrin Capital Management


On Jun 19, 2010, at 7:46 AM, Michael A. Gilchrist wrote:

David Park

unread,
Jun 20, 2010, 3:57:07 AM6/20/10
to
The Presentations package has a UnitBar primitive. You can create bars with
the various characteristics of the bars in BarChart, and then scale and
transport them to whatever locations you wish. You could have horizontal
bars, or put the bars on the perimeter of a circle or whatever. You could
combine them and tailor them as you wish and easily combine with other
graphics.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

0 new messages