3
$\begingroup$

I am not sure what I am doing wrong in my code. I just want illustrate four columns consisted of different numbers as plot markers.

ListPlot[{{1, 2, 3, 4}, {2, 1}, {2, 2}, {3, 1}, {3, 2}, {4, 1}, {4, 2}},
PlotMarkers -> {"\[Pi]", "8", "9", "10", "2", "5", "3", "4", "1", 
"\!\(\*SqrtBox[\(2\)]\)"}, Ticks -> None, AxesLabel -> {"Number of 
columns", "Size of the columns"}]

But I get this plot output:

enter image description here

Any help or a hint will be greatly appreciated.

Thank you.

UPDATE: I have figured out the wrong format of my code thanks to @Graumagier.

But, I have searched in google how to change the scale of the x-axis because automatically in the plot the coordinates with $x=1$ are very close to the y-axis. Is there any way to adjust that?

enter image description here

$\endgroup$
9
  • $\begingroup$ You'll at least need another set of {} for each of the one-element lists ({{2, 1}}, {{2, 2}}, {{3, 1}}, {{3, 2}}, {{4, 1}}, {{4, 2}}), otherwise ListPlot won't interpret them as points with two coordinates, but as lists of two points. And I'm not really sure what you're trying to do with {1,2,3,4}. $\endgroup$
    – Graumagier
    Nov 6, 2015 at 12:17
  • $\begingroup$ @Graumagier I want to write {1,1},{1,2},{1,3},{1,4} but followed an example here where uses different code:ListPlot[{{1, 2, 3, 5, 8}, {2, 3, 6, 9, 10}, {4, 5, 7, 10, 12}}, PlotMarkers -> {"\[Alpha]", "\[Beta]", "\[Gamma]"}] $\endgroup$
    – johnny09
    Nov 6, 2015 at 12:21
  • $\begingroup$ I see. You can do it this way, but you have to decide whether you want to plot a list of x values with automatic y values (e.g. {1,2,3} corresponding implicitly to {{1,1},{2,2},{3,3}}) or lists of points with explicit x and y coordinates (e.g. {{1,2}}), in which case you have to make sure to use the right (double) parentheses. You can mix those of course, but if you get duplicate points in the process you end up with overlaying labels like in your case. $\endgroup$
    – Graumagier
    Nov 6, 2015 at 12:26
  • 3
    $\begingroup$ In this case you'd have to write ListPlot[ {{{4, 1}}, {{4, 2}}}, PlotMarkers -> {"1", Sqrt[2]} ]. Here's an example of mixed list formats, maybe that will make it clearer: ListPlot[ {{1, 2, 3, 4}, {{2, 1}}, {{3, 2},{3, 4}}}, PlotMarkers -> {"1", Sqrt[2], "3"} ]. $\endgroup$
    – Graumagier
    Nov 6, 2015 at 12:36
  • 1
    $\begingroup$ Use PlotRange-> {{0, 5}, Automatic} to control the scale on the x axis. $\endgroup$ Nov 6, 2015 at 13:50

1 Answer 1

6
$\begingroup$

General information about list formats with ListPlot

You have to make sure to use the right format for the lists of points. ListPlot takes three formats, as you can see in the function's documentation:

Here you provide multiple y values which get assigned consecutive x values automatically by ListPlot. All the points are treated as belonging to the same dataset:

{y1, y2, …}

Here you provide multiple points with explicit x and y values. Each point is a list with two coordinates, and they get treated as points of the same dataset:

{{x1, y1}, {x2, y2}, …}

Here you provide multiple lists with one or more points each. Each list of lists get treated as a separate dataset:

{{{x11, y11}, {x12, y12}}, {{x21, y21}, {x22, y22}}, …}

Concerning your specific case

The distinction between the last two is important in your case, because ListPlot loops over datasets in order to decide which PlotMarkers to assign to which points.

Here's an example of mixed list formats in order to plot (1) a number of y values with implicit x coordinates, (2) a single point with explicit x and y coordinates and (3) a list of two points, each with explicit x and y coordinates. Each of these datasets gets a separate value in PlotMarkers:

ListPlot[
  {
    {1, 2, 3, 4}, 
    {{2, 1}},
    {{3, 2}, {3, 4}}
  },
  PlotMarkers -> {"1", Sqrt[2], "3"}
]

ListPlot with multiple datasets, each with a unique plot marker.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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