What I am trying to do is create something that looks like this,
which I have created by using the Octave pcolor and barh functions using 3 subplots with the subplot x axes scaled to look as if the figure were one plot. However, this approach is unsatisfactory as I cannot zoom or pan across it as I would be able to if it were actually one plot.
How can I plot one background figure using pcolor and then add multiple y axes at different points along the x axis to plot the horizontal histograms using barh?
For some background to this question, I am trying to create what is called a Market Profile chart, i.e. see example here or here.
I have also cross posted this question on the Octave mailing list here.
I have found a way to do what I want. Instead of using the barh function, one can use the fill function instead.
A minimal, reproducible example given below.
## create y and x axes for chart
y_max = max( high_round ) + max_tick_range * tick_size ;
y_min = min( low_round ) - max_tick_range * tick_size ;
y_ax = ( y_min : tick_size : y_max )' ;
end_x_ax_freespace = 5 ;
x_ax = ( 1 : 1 : numel( open ) + end_x_ax_freespace )' ;
colormap( 'viridis' ) ; pcolor( x_ax , y_ax , vp_z' ) ; shading interp ; axis tight ;
## plot the individual volume profiles
hold on ;
scale_factor = 0.18 ;
fill( vp( 1 , : ) .* scale_factor , y_ax' , [99;99;99]./255 ) ;
fill( vp( 2 , : ) .* scale_factor .+ 50 , y_ax' , [99;99;99]./255 ) ;
fill( vp( 3 , : ) .* scale_factor .+ 100 , y_ax' , [99;99;99]./255 ) ;
hold off;
More details on a blog post of mine.
Related
i want to plot a contour of PBLH difference between 2 wrf-chem simulations. I have the netcdf means (attached files), and i want to draw contour of 95% significance levels, but the script did not work, can you give your suggestions please?
"Error: scalar_field: If the input data is 1-dimensional, you must set sfXArray and sfYArray to 1-dimensional arrays of the same length.
warning:create: Bad HLU id passed to create, ignoring it"
i'm explecting a contour plot with Grey shaded areas indicate regions with less than 95 % significance.
here is the code. You can test it with any two WRF netcdf files:
`;----------------------------------------------------------------------
; contoursym_1.ncl
;
; Concepts illustrated:
; - Using a symmetric color map
; - Using a blue-red color map
; - Explicitly setting contour levels
;----------------------------------------------------------------------
;
; These files are loaded by default in NCL V6.2.0 and newer
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRF_contributed.ncl"
; This file still has to be loaded manually
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
begin
;*****************
;-- load data
;*****************
;specify file names (input&output, netCDF)
pathin = "./" ; directory
fin1 = "15-25-omet.nc" ; input file name #1
fin2 = "15-25-wrfda.nc" ; input file name #2
fout = "signif_pblh_omet-wrfda" ; output file name
foutnc = fout+".nc"
f = addfile ("15-25-omet.nc", "r")
; open input files
in1 = addfile(pathin+fin1,"r")
in2 = addfile(pathin+fin2,"r")
; read data
tmp1 = in1->PBLH
tmp2 = in2->PBLH
x = f->PBLH(0,:,:)
diff=tmp1-tmp2
printVarSummary(tmp1)
printVarSummary(tmp2)
;****************************************************
; calculate probabiliites
;****************************************************
;t-test
res1=True
xtmp=tmp1(XTIME|:,south_north|:, west_east|:)
ytmp = tmp2(XTIME|:,south_north|:, west_east|:)
aveX = dim_avg_Wrap(xtmp)
aveY = dim_avg_Wrap(ytmp)
varX = dim_variance(xtmp)
varY = dim_variance(ytmp)
sX = dimsizes(xtmp&XTIME)
sY = dimsizes(ytmp&XTIME)
print(sX)
print(sY)
alphat = 100.*(1. - ttest(aveX,varX,sX, aveY,varY,sY, True, False))
;aveX = where(alphat.lt.95.,aveX#FillValue, aveX)
;print(alphat)
;*********************
;---Start the graphics
;**********************
wks = gsn_open_wks("ps" ,"Bias_gray_F") ; ps,pdf,x11,ncgm,eps
res = True
res#gsnMaximize = True ; uncomment to maximize size
res#gsnSpreadColors = True ; use full range of colormap
res#cnFillOn = True ; color plot desired
res#cnLinesOn = False ; turn off contour lines
res#cnLineLabelsOn = True ; turn off contour labels
res#cnLineLabelsOn = True ; turn on line labels
res#lbOrientation = "Vertical"
res#lbLabelPosition = "Right" ; label position
res#tiMainFontHeightF = 0.025
res#lbBoxEndCapStyle = "TriangleBothEnds" ; triangle label bar
;************************************************
; Use WRF_contributed procedure to set map resources
;************************************************
res = True
WRF_map_c(f, res, 0) ; reads info from file
;************************************************
; if appropriate, set True for native mapping (faster)
; set False otherwise
;************************************************
res#tfDoNDCOverlay = True
;************************************************
; associate the 2-dimensional coordinates to the variable for plotting
; only if non-native plot
;************************************************
if (.not.res#tfDoNDCOverlay) then
x#lat2d = f->XLAT(0,:,:) ; direct assignment
x#lon2d = f->XLONG(0,:,:)
end if
;************************************************
; Turn on lat / lon labeling
;************************************************
res#pmTickMarkDisplayMode = "Always" ; turn on tickmarks
;res#tmXTOn = False ; turn off top labels
;res#tmYROn = False ; turn off right labels
;************************************************
; Loop over all times and levels ( uncomment )
; Demo: one arbitrarily closen time and level
;************************************************
dimx = dimsizes(x) ; dimensions of x
ntim = dimx(0) ; number of time steps
klev = dimx(1) ; number of "bottom_top" levels
nt = 0 ; arbitrary time
kl = 6 ; " level
opt=True
opts=True
res1=True
res = opts ; Use basic options for this field
opts#MainTitle = "OMET-FBDA"
opts#InitTime = False ; Do not plot time or footers
opts#Footer = False
plot0 = gsn_csm_contour_map(wks,diff(0,:,:),res ) ; define plot 0
pval = gsn_csm_contour(wks,alphat(0,:),res1) ;-- this adds a contour line around the stippling
opt#gsnShadeMid="gray62"
pval = gsn_contour_shade(pval,0.05,1.00,opt) ;-- this adds the stippling for all pvalues <= 0.05
overlay(plot0,pval)
draw(plot0)
frame(wks)
end`
Does a function exist that is similar to rlim in matlab? I need to modify a polar plot for an antenna diagram where the 0 is on the outer rim and all values are negative.
The result should in general (!) look like this picture. Only the scaling (not the ticks) on the radial axes is relevant, though.
Ok, I'll provide an example for the sake of demonstrating what I was on about:
t = 0 : 0.01 : 2 * pi;
r = abs( 2 + 5 * sin( 3 .* t ) .* ( 1 + 2 * pi .* t - t .^ 2 ) );
p = polar( gca, t, r );
set( groot, 'showhiddenhandles', 'on' )
TTicks = [ 0 : 45 : 315 ]; % Note: here, specified in degrees
RTicks = [ 20 : 20 : 100 ]; % Note: 'zero' not included!
set( gca, 'ttick', TTicks );
set( gca, 'rtick', RTicks );
NumTticks = length( TTicks );
NumRticks = length( RTicks ); % will only be correct if zero was excluded above.
PolarGrid = findobj( gca, 'tag', 'polar_grid' );
Handles = get( PolarGrid, 'children' );
NumHandles = length( Handles );
% The children are arranged as follows:
% NumTticks handles: text objects that make up the ttick labels (from last to first)
% NumTticks handles: line objects that make up the ttick gridlines
% NumRticks handles: text objects that make up the rtick labels (from last to first)
% NumRticks handles: line objects that make up the rtick concentric gridlines
% Last handle : A darker line, coinciding with the last rtick gridline, serving as the outline.
% Therefore, to change the rticklabels:
RTickLabelHandles = Handles( NumHandles - NumRticks - [1 : NumRticks] );
RTickLabels = { '', '30db', '20db', '10db', '0' };
for i = 1 : NumRticks, set( RTickLabelHandles(i), 'string', RTickLabels{i} ), end;
But, having said that, if your requirements deviate to such an extent from what the polar function is expected to provide (including a custom 0 angle orientation), then you're right, it's probably better to simply draw all the elements yourself from scratch (including grid circles and custom labels).
I'm struggling with setting a y(x) condition that varies with x range. As an example below, the code wants to plot y=x between x=0 and x=5.1; otherwise y=2x.
Upon compilation, the code spits out the following: Expression must be a scalar or 1 element array in this context:
In other words don't know how to assign an array variable 'x' into if statement.
Thank you all for your help in advance.
PRO test
x = findgen(101.0,start=0)/10.0 ; 0.0 start, 10.0 end increment of 0.1
print,x
if x lt 5.1 then begin
y = 1.0 * x ;
endif else begin
y = 2.0* x
endelse
graph1=plot(x,y,thick=2,NAME=first,/CURRENT, $
linestyle = 0, ytitle=' y',xtitle='x' ) ; O
END
The problem is the test in your IF statement. Use WHERE instead to do something like the following.
y = x ;; need to initialize variable
low = WHERE(x lt 5.1,lw,COMPLEMENT=upp,NCOMPLEMENT=up)
IF (lw[0] GT 0) THEN y[low] = x[low] ;; technically don't need this line
IF (up[0] GT 0) THEN y[upp] = 2e0*x[upp]
My question is identical to this question except that I'm using conditional coloring for candlesticks and the solution mentioned isn't working.
My data is like:
10/24/2018 23:45,168.25,168.65,168.2,168.4,0
10/24/2018 23:46,168.5,169,168.5,168.95,67577
10/24/2018 23:47,169.35,169.6,169.1,169.1,151630
10/24/2018 23:48,169.05,169.35,168.95,169.2,63418
.
.
10/26/2018 13:48,169.05,169.35,168.95,169.2,63418
10/26/2018 23:47,169.35,169.6,169.1,169.1,151630
10/26/2018 23:48,169.05,169.35,168.95,169.2,63418
Plotting a file like this in gnuplot using command:
plot ".../ISTFeed.csv" using (timecolumn(1, "%m/%d/%Y %H:%M:%S")) : 2 : 3 : 4 : 5 : ($5 < $2 ? rgb(255, 0, 0) : rgb(0, 255, 0)) linecolor rgb variable notitle with candlesticks
produces chart with gaps. I want gnuplot to omit the gaps and plot candlesticks continuously. Is there a way to achieve this?
Have a look at the below example with generated dummy data. Although the xtics in the plot look equidistant the values of the xtics are not equidistant at all. So if you want to readout a y-value between two xtics you don't have "any" idea what the actual x-value is. You just know it must be somewhere inbetween the neighbouring xtics. A bit strange... but if you are fine with this precision...
Code:
### remove gaps in timedata
# requires gnuplot >=5.2, because of use of datablocks
reset session
# generate some dummy data
t = strptime("%m/%d/%Y %H:%M", "10/24/2018 23:45")
close = 168.25
set print $Data
print "# date time, open, low, high, close"
do for [i=1:100] {
open = close + (rand(0)*2)-1
low_tmp = open - rand(0)
high_tmp = open + rand(0)
close = open + (rand(0)*2)-1
low = open<low_tmp ? open : close<low_tmp ? close : low_tmp
high = open>high_tmp ? open : close>high_tmp ? close : high_tmp
dt = 3600*rand(0)*48
t = t + dt
print sprintf("%s,%8 .2f,%8 .2f,%8 .2f,%8 .2f",strftime("%m/%d/%Y %H:%M",t),open,low,high,close)
}
set print
print $Data
N = 10
Offset = 5
everyNthRow(N) = (int($0)%N==Offset ? word(strcol(1),1) : NaN)
set datafile separator ","
set xtics rotate by 45 right
set style fill solid 1.0
plot $Data u 0:2:3:4:5:($5<$2 ? 0xff0000 : 0x00ff00):xtic(everyNthRow(N)) w candlesticks lc rgb var not
### end of code
Result:
I have a 3d game where I will create an rectangle which is working as screen and the game itself works with vectors to positions. so I will create an rectangle and have only these parameters aviable:
start position ->vector (x,y,z).
Angle(rotation) of object(x,y,z).
size of rectangle.
now also the object need to be roatet to the right side so they are using angels also (x,y,z).
example:
position:-381.968750 -28.653845 -12702.185547
angle: -0.000 90.000 90.000
What I will create is an little bit hard but as idea simple.
I choose 2 complete different positions and angles and will create from the first vector to the second an rectangle.
I can only create an rectangle with the start point and angle.
and I can set the size so (x,y)
So I will now insert 2 positions(vectors) with 2 different angles
The rectangle will have the middle value between the first and second angle so like (90 and 0) -> 45
And the rectangle will start at the start vector and will end with his own size so I don't have a chance to use the end vector directly.
Legendary on photo:
Green=>start and end positions(vectors).
red => the marked zone.
Blue => how I will have the rectangle.
aem_point = vgui.Create( "AEM.Main.Panel" )
if IsValid(aem_point) then
aem_point:SetSize( 2,2 ) -- <-the size that i can set
aem_point:SetPos( 0, 0 )
aem_ph = vgui.Create( "DHTML", aem_point )
aem_ph:SetSize( aem_point:GetSize() )
aem_ph:SetPos(aem_point:GetPos())
aem_ph:SetVisible( true )
aem_ph:SetHTML([[
<html>
<body style="margin:0px;padding:0px;font-size:20px;color:red;border-style: solid;border-color: #ff0000;background-color:rgba(255,0,0,0.1);">
</body>
</html>
]] )
end
hook.Add( "PostDrawOpaqueRenderables", "DrawSample3D2DFrame" .. math.random(), function()
if first and dat_finish then
vgui.Start3D2D( input_position, input_angle, 1 ) -- <-and position&vec
aem_point:Paint3D2D()
vgui.End3D2D()
end
end )
Oh so you want to create a 3d2d plane from 2 vector positions?
Vec1 = A
Vec2 = B
input_position = ( Vec1 + Vec2 ) / 2
A problem you will run into is you need 3 points to generate a plane, so while you can get the position of the screen to get the angle of it you will need another point.
If these screens of yours are staticly set, as in you put their position into the lua code manually and dont intend to have it move or anything, just manually putting in the angle is by far the most simple approch.
As you can see, both of these planes are on the same two points, but they have diffrent angles.
I wrote the demo in expression 2, this should make it clear as to how this works, if you have any other questions just ask.
A = entity(73):pos()
B = entity(83):pos()
if(first())
{
holoCreate(1)
holoCreate(2)
}
holoPos(1,(A+B)/2)
holoScaleUnits(1,vec( abs(B:y() - A:y()) , 1 , abs(sqrt( ( B:z() - A:z() ) ^ 2 + ( B:x() - A:x() ) ^ 2 ))))
holoAng(1,ang(0,90,45))
holoPos(2,(A+B)/2)
holoScaleUnits(2,vec( abs(sqrt( ( B:x() - A:x() ) ^ 2 + ( B:y() - A:y() ) ^ 2 )) , 1 , abs(B:z()-A:z())))
holoAng(2,ang(0,45,0))