User:Andrew Nikitin/plothacks

From J Wiki
Jump to: navigation, search

Hollow markers

When datapoints in type marker scatterplots comes too close together, it is difficult to judge how many of them are in close vicinity. Markers being circular and hollow helps.

NB. ==== plot hack: hollow markers instead of full markers
isimarker_jzplot_=: 3 : 0
's m f e c p'=. y
p=. gpflip p
NB. HERE WAS:  gpbuf gppenbrush1 e
gpbuf 5 2032,(,e),4 2022 1 0 2 2005
s ('isimark_',m)~ p

-- <<DateTime(2010-07-16T14:34:38-0400)>>

Save bitmap

The following command saves currently open plot window as a bitmap of exctly same size as it is on the screen.

pd 'save bmp z.bmp ',":_2{.Pxywh_jwplot_

-- <<DateTime(2010-07-16T14:34:38-0400)>>


This handler prints x and y coordinates of a point in plot axis units upon doubleclick on plot area.

plot_gs_mbldbl_jwplot_=:3 : 0
  if. *./(xy>:2{.Gxywh),(xy<: 2 ({. + }.)Gxywh) do.
    px=.XMin +(XMax-XMin)*(2{Gxywh)%~({.xy)-(0{Gxywh)
    py=.YMin +(YMax-YMin)*(3{Gxywh)%~((3{Pxywh)-{:xy)-(1{Gxywh)
    smoutput 'x,y=',":px,py

-- <<DateTime(2010-07-16T16:04:42-0400)>>

Copy working plot

NB. may need P0=:conew 'jzplot'
do__P0 'pd ''show'' [ PCmd=:PCmd_jwplot_ [ pd ''reset'''

Copy plot data from working plot jwplot into named (P0) and redisplay it.

-- <<DateTime(2010-07-29T13:08:14-0400)>>

Save plot as .ijs script

NB.*psj v save currently open plot as ijs script
psj=:3 : 0
  f=.'require ''plot''',CRLF
  f=.f,'pd ''reset''',CRLF
  e=.CRLF,'pd ''show''',CRLF
  e=.e,'wd ''pmovex '',":',(":wd 'qformx'),CRLF
  (f , (5!:5 <'PCmd_jwplot_') , e) 1!:2 boxopen y
  i.0 0

Saves plot settings, data and window position and location in J script file. When this file is run, it reproduces original plot.

-- <<DateTime(2010-07-29T14:09:29-0400)>>

Custom color scheme -- MAP

   MAPCLR_jzplot_=: 64 colorxy_jzplot_ 0 0 0.3, 0 1 1,1 1 0,0.8 0.2 0,i.0 0
   k=.(,|.) (1+i.5)
   'bandcolor mapclr;type density' plot (1 1,:2##k) (k +/ . * ] +/ . * k"_);._3 ?100 100$0

Specify set of colors for density (and contour) plots. Example shows bandcolor that resembles geographic maps, with deep blue depths, cyan shallows, green lowlands and yellow to orange to brown highlands.

-- <<DateTime(2010-08-03T16:09:31-0400)>>

Scroll plot horizontally

See plotscroll

-- <<DateTime(2010-08-04T13:22:11-0400)>>

Force X axis units equal to Y axis units


'type poly' plot 0 1j5+/^ 0j2p1 * (%~ i.) 5

displays 2 offset regular pentagons. Pentagons may not look regular depending on the proportions of the plot window. The following command forces X axis units to become Y axis units on the already displayed plot, so that in our case pentagons will look regular.

pd 'aspect ',(":do_jwplot_ '(YMax-YMin)%(XMax-XMin)'),';show'

-- <<DateTime(2010-08-12T16:16:09-0400)>>

Tweak viewpoint in 3D plot

plot3dview shows how to do that. Requiers adjuster

-- <<DateTime(2010-08-20T17:04:58-0400)>>

Clone plot in a new window

NB.*pclone v creates a clone of plot y, '' defaults to 'jwplot'
pclone_jzplot_=:3 : 0
  if. a:-:y=.boxopen y do. y=.<'jwplot' end.
  pd 'show'

This is a way to "freeze" plot that had been interactively constructed by issuing pd commands. Call as pclone__P0 '', assuming P0=:conew 'jzplot' has been done previously.

-- <<DateTime(2011-05-12T10:04:12-0400)>>

Use minus instead of hyphen for negative labels

Mathematical minus sign (−) is different from hyphen (-), which is actually used by plot to format negative numbers. Minus is wider and is located a little bit higher (on the same level as horizontal part of +). Most of the time it does not matter, when it does the following hack to the label formatting verb fixes it.

lfmt_jzplot_=:3 : 0
dat=. ": y
txt=. ,dat
utf8 (u:8722) (I. txt='_') } txt

-- <<DateTime(2011-05-13T17:09:04-0400)>>

pclose fix

When jwplot is mixed with instances of other jzplots, sometimes an attempt to close it (jwplot) causes one of the other instances of jzplot to close.

This is the fix.

pclose_jzplot_=:3 : 0
  if. ifjwplot'' do.
    NB. this still might select wrong window and save position of one of jzplots
    wpsave_j_ :: 0: PForm
  wd 'psel ',PFormhwnd
  wd 'pclose'
  pd 'reset'

-- <<DateTime(2011-05-17T10:54:46-0400)>>

Resize plot window

plotsize=:3 : 0
(<'jwplot') plotsize y
  wd 'psel ',PFormhwnd__x
  'o s'=._2 ]\ ".wd'qformx'
  wd 'pmovex ',":o,+/y,:MRG

-- <<DateTime(2013-09-05T09:35:57-0400)>>