Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.4K Views
|
8 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Write a generated image to another notebook?

Posted 8 months ago

I'm learning the NotebookWrite[] interface and have hit a wall on inserting images.

What I've done is a script that generates a map that I then want to insert the image that results from the code into the daily notebook, but everything I've tried thus far instead inserts the raw code, not the map image.

POSTED BY: Steven Buehler
8 Replies
Posted 8 months ago
POSTED BY: Steven Buehler
POSTED BY: Michael Rogers
Posted 8 months ago

The code you offered had an error ([] where it didn't belong) and when run only entered the "New Content" subsection and not the image.

POSTED BY: Steven Buehler

Sorry about the []. It wasn't in the code I pasted. Probably it got there when editing. For some reason, the mouse clicks are mapped to the wrong location when I'm using the editor. Sometimes I don't see where I've typed. Anyway I took it out.

Works perfectly for me. Don't know why it wouldn't work for you.

I commented out the second line. It's not necessary and may be a distraction. Works either way for me anyway.

As I understand your reply, nothing is written into nb by the last NotebookWrite[], which seems strange. And no error (I suppose).

POSTED BY: Michael Rogers
Posted 8 months ago

Okay, the following worked, although the graphic size was rather small (I'll need to figure out the sizing). I guess I need to wrap larger code in Module or something...

nb = CreateDocument[];
GeoGraphics[GeoMarker[Here]] // 
 NotebookWrite[nb, 
   Cell[BoxData[MakeBoxes[#, StandardForm]], "Output"]] &
POSTED BY: Steven Buehler

Great. For me, the created notebook has an image a few pixels larger than the standard output of GeoGraphics[GeoMarker[Here]]. In any case, there's the ImageSize option you can use to control the size of the output image.

POSTED BY: Michael Rogers
Posted 8 months ago

The actual application is as follows (the token obscured for obvious reasons):

nb = CreateDocument[];
data = {};
offset = 0;
checkins = 
  Import["https://api.foursquare.com/v2/users/self/checkins?limit=250&\
v=20231001&oauth_token=XXXXXXXXXXXXXX", "RawJSON"][["response", 
    "checkins", "items"]];
While[Length[checkins] > 0,
      Do[
   	PrependTo[checkins[[i]], 
    "timestamp" -> FromUnixTime[checkins[[i, "createdAt"]]]];
   	AppendTo[data, checkins[[i]]]
   	, {i, Length[checkins]}
   ];
  offset += 250;
  checkins = 
   Import["https://api.foursquare.com/v2/users/self/checkins?offset=" \
<> ToString[offset] <> "&limit=250&v=20231001&oauth_token=XXXXXXXX", 
     "RawJSON"][["response", "checkins", "items"]];	
  ];
GeoListPlot[Table[
   GeoPosition[{data[[i, "venue", "location", "lat"]], 
     data[[i, "venue", "location", "lng"]]}]
   , {i, Length@data}], 
  GeoBackground -> {"VectorClassic", "StreetMapLabelsOnly"}, 
  ImageSize -> Large] // 
 NotebookWrite[nb, 
   Cell[BoxData[MakeBoxes[#, StandardForm]], "Output"]] &
POSTED BY: Steven Buehler
POSTED BY: Ahmed Elbanna
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard