Message Boards Message Boards

0
|
3549 Views
|
8 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Unexpected behavior in ListLinePlot?

I create an array of images with ListLinePlots. All that the images are are set of sets of 4 points forming 3 lines. I tried to arrange for my lines to use the full range of the frame with an aspect ratio of 1x1. I have it so that the X axis starts at the minimum value of the data and the Y axis starts at 0 while the top of the Frame is at the maximum Y. I've attached as simple notebook so that you can see how the images comes up properly. However, when I am plotting a number of such plots, most of them are printed correctly, spanning the range of [Ymin,Ymax] on the Y axis BUT some of them still show the chart with a lot of space below the Minimum Y and above the Maximum Y. Please see the attached notebook for more information:

POSTED BY: Henrick Jeanty
8 Replies
Posted 2 years ago

Thank you Rohit. Your last suggestion worked! When I tried to Binarize, I received the error shown previously. I will try your code.

POSTED BY: Updating Name
Posted 2 years ago

Oh, finally I think I get it. How about this?

plots = ListLinePlot[#,
    Background -> Black,
    ImageSize -> {128, 128},
    Frame -> False,
    Axes -> False,
    AspectRatio -> 1,
    PlotRange -> CoordinateBounds@#,
    PlotMarkers -> {{\[FilledCircle], 2}}] & /@ images

enter image description here

You can use Scaled if you want to add some padding so the plot markers are completely visible. Check the documentation for CoordinateBounds.

I found that Binarize doesn't produce an image with just 0's and 1's

How did you determine this?

If you are using a color sampler on the image rendered on a screen/monitor then that is the result of anti-aliasing in the display of the image, not the image itself.

There are only 0's and 1's in the image

plots // Map[Binarize /* ImageData /* Flatten /* Counts]
(* {<|0 -> 63554, 1 -> 1982|>, <|0 -> 63225, 1 -> 2311|>, <|0 -> 63500, 1 -> 2036|>} *)
POSTED BY: Rohit Namjoshi

Hello Rohit. Yes, the full range of data is plotted, but what you show in the last 3 binarized images is not what I wish for. In your last images, the Minimum Y coordinate (leftmost point in images 1, 3rd point in images 2 and 3) should be on the X axis (or as close as the graphics will allow) and the Maximum Y should be at the top of the image. I read up on this where, for instance there was an option to provide where the X and Y axes should intersect and (in my case that would be at the (Xmin,Ymin) location (which is not necessarily one of the points, see images 2 and 3). This would force the lowest point to sit on the X axis and the highest point to touch the top of the Chart. I absolutely don't want ant space above or below the 4 points. Also , since you are responding, I found that Binarize doesn't produce an image with just 0's and 1's, How can I make sure that the "Binarized" images I obtain are TRUE binary images with just 0's and 1's.

POSTED BY: Henrick Jeanty

I could, but I want to understand why a number of charts come out exactly as I want them (using the full range of the chart in the Y direction) while a few only use part of the Y range. For instance, I provide you with 3 sets of points, the ListLinePlot command I use on them and how they come out. Please take a look at the top of the notebook I provide. It is also about binarizing an image, but for now, I will be happy if I can consistently plot using the full range of the chart.

POSTED BY: Henrick Jeanty
Posted 2 years ago

The full range of the data is plotted, it is the origin that is different. Is this what you are looking for?

plots = ListLinePlot[#,
   Background -> Black,
   ImageSize -> {128, 128},
   Frame -> True, 
   Axes -> False, 
   AspectRatio -> 1,
   PlotRange -> All,
   AxesOrigin -> {0, 0},
   PlotMarkers -> {{\[FilledCircle], 2}}] & /@ images

enter image description here

Regarding Binarize, it requires an Image or Graphics as input. Framed changes the Head to Framed. So, Binarize first, then add Framed.

plots = ListLinePlot[#,
    Background -> Black,
    ImageSize -> {128, 128},
    Frame -> False, 
    Axes -> False, 
    AspectRatio -> 1,
    PlotRange -> All,
    AxesOrigin -> {0, 0},
    PlotMarkers -> {{\[FilledCircle], 2}}] & /@ images

Binarize /* Framed /@ plots

enter image description here

POSTED BY: Rohit Namjoshi

What about calculating Max[max1,max2,...] and the same for Min?

POSTED BY: Hans Dolhaine

This would work if I were just plotting a single image of 3 lines. But when I am plotting multiple lists of coordinates, each list will have a different min, max. So, calculating the mins and maxes for X and Y would only be valid for one of the lists of coordinates.

POSTED BY: Henrick Jeanty

What about this?

pts = {{0, 217.3000030517578`}, {15, 158.83999633789062`}, {42, 
   248.83999633789062`}, {43, 237.8699951171875`}}

xmin = .8 Min[Transpose[pts][[1]]]
xmin = -5
xmax = 1.2 Max[Transpose[pts][[1]]]
ymin = .8 Min[Transpose[pts][[2]]]
ymax = 1.2 Max[Transpose[pts][[2]]]

Table[
 ListLinePlot[pts, ImageSize -> {128, 128}, Frame -> True, 
  Axes -> False, Ticks -> False, AspectRatio -> 1, 
  PlotMarkers -> {{\[FilledCircle], 8}},
  PlotRange -> {{xmin, xmax}, {ymin, ymax}}],
 {n, 1, Length[pts]}]
POSTED BY: Hans Dolhaine
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract