8
$\begingroup$

When I thought to vary PointSize on a ListPlot, I expected to find it trivial to do. I've likely overlooked something simple, but I've found it quite curious.

Reducing the problem to some simple examples:

ListPlot[{0.1, 0.2, 0.3}] 
ListPlot[{0.1, 0.2, 0.3}, PlotStyle -> (PointSize[#] & /@ {Small, Medium, Large})]
ListPlot[{{0.1}, {0.2}, {0.3}}, PlotStyle -> (PointSize[#] & /@ {Small, Medium, Large})]
ListPlot[{{1, 0.1}, {2, 0.2}, {3, 0.3}}, PlotStyle -> (PointSize[#] & /@ {Small, Medium, Large}), PlotRange -> {{0, 3}, Automatic}]

plots

The 1st plot shows the starting plot with no PlotStyle set.

The 2nd plot shows an attempt to size the individual points. This does not work either, but the documentation for PlotStyle explains why:

PlotStyle documentation

The 3rd plot makes each value in the original list its own object. This sizes the points properly, but does not plot them as I would like along the x axis.

The 4th plot adds position values for each object's point, but now I've lost the PointSizing.

Any suggestions on how to do this?

Any explanation of the paradigm involved in doing this properly?

$\endgroup$
  • $\begingroup$ @Öskå Correct, as illustrated below. :-) $\endgroup$ – Mr.Wizard Sep 28 '14 at 15:47
  • $\begingroup$ @Mr.Wizard Correct ;-D $\endgroup$ – Öskå Sep 28 '14 at 15:50
6
$\begingroup$

Your forth input form is not three sets of points but rather one set in {x, y} form. Adding an additional set of brackets gives the output you desire:

ListPlot[{{{1, 0.1}}, {{2, 0.2}}, {{3, 0.3}}}, 
 PlotStyle -> (PointSize /@ {Small, Medium, Large}), 
 PlotRange -> {{0, 3.1}, Automatic}]

enter image description here

$\endgroup$
  • $\begingroup$ Ah! Yet another mystery revealed as not a mystery. Thank you. $\endgroup$ – Jagra Sep 28 '14 at 15:51
8
$\begingroup$
data = Table[{x, Sin[x]}, {x, -Pi, Pi, 0.1}];
Graphics[{Hue[#2], PointSize[Abs[#2]/50], Point[{#1, #2}]} & @@@ data,
  Axes -> True]

enter image description here

$\endgroup$
5
$\begingroup$

Just for fun

data = Table[{x, Sin[x]}, {x, -Pi, Pi, 0.1}];

ListPlot[List /@ data, 
 GridLinesStyle -> Black,
 ImageSize -> 500,
 PlotStyle -> PointSize /@ (Abs[Last /@ data]/30),
 PlotMarkers -> None,
 PlotTheme -> "Marketing"]

enter image description here

BubbleChart[Table[{Sin[2 x], Cos[2 x], Exp[x]}, {x, -2 Pi, 2 Pi, 0.2}],
 ColorFunction -> "BeachColors",
 Frame -> False,
 GridLines -> None,
 PlotTheme -> "Marketing"]

enter image description here

$\endgroup$
  • $\begingroup$ What is the pretty thing Mr.Wizard -:) $\endgroup$ – Algohi Sep 28 '14 at 17:20
  • $\begingroup$ @Mr.Wizard LOL, "circus caterpillar" is a nice notion of what I wanted to create. But, seriously, I just felt that BubbleChart is a tiny bit underrepresented at SE :) $\endgroup$ – eldo Sep 28 '14 at 20:26
4
$\begingroup$

An alternative to breaking the data into individual elements and using different PlotStyles for each element is to wrap individual elements with Style:

data = {0.1, 0.2, 0.3};
colors = {Red, Green, Blue};
pointsizes = PointSize /@ {.06, Medium, Large};

You can apply styling directives to individual elements in several ways:

styleddata1 = Style @@@ Thread[{data, colors, pointsizes}];
styleddata2 = Thread[Style[data, colors, pointsizes]];
styleddata3 = MapThread[Style, {data, colors, pointsizes}];

ListPlot[#, PlotRange -> {{0, 3.1}, {0, Automatic}}, ImageSize -> 350] & /@
    {styleddata1, styleddata2, styleddata3} // Row

enter image description here

$\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.