Transparency in plotted surfaces - octave

I'm using Octave 7.2.0-1 on linux.
When plotting surfaces which overlap (both with facealpha<1) Octave only shows the axes as a "see-through", not the surface which is "behind":
[ xs, ys, zs ] = sphere( 20 );
surf( xs, ys, zs, 'facealpha', 0.5, 'edgealpha', 0.5, 'facecolor', 'r' );
hold on
surf( xs+1, ys+1, zs , 'facealpha',0.5, 'edgealpha', 0.5, 'facecolor', 'g');
Is this a bug?

Related

plotting multiple graphs on the same figure in Octave

I'm trying to plot multiple graphs on a single figure in Octave. Here is my code: these graphs represents the decrease of the cost function on each iteration of gradient decent:
% Init Theta and Run Gradient Descent
theta = zeros(3, 1);
[theta, J_history] = gradientDescentMulti(X, y, zeros(3, 1), alpha, num_iters);
[theta1,J1]=gradientDescentMulti(X, y, zeros(3, 1), 0.05, num_iters);
[theta3,J3]=gradientDescentMulti(X, y, zeros(3, 1), 0.03, num_iters);
% Plot the convergence graph
figure;
plot(1:numel(J_history), J_history, 'g', 'LineWidth', 2);
hold on;
plot(1:50, J2, 'r');
plot(1:50, J3, 'b');
xlabel('Number of iterations');
ylabel('Cost J');
However, when I run the codes, I got only one graph on the figure without even the labels, The best I was able to d was to put two graph on the same figure:
Is there something wrong with my codes?

size mismatch, m1: [1 x 512], m2: [25088 x 4096] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:2070

Goal: Use pretained VGG16 to classify CIFAR-10 Images.
Please, see this link to have an overview:
https://colab.research.google.com/drive/10Wo95j3h7h7QMd8Xpueb50ieawxw5b4M

Creating a 2 line graph on left axis and a bar graph on right axis Octave

I'm having difficulty creating a 2 y axis graph in Octave. Currently I can make the 2 line graph. However, I haven't been able to find a function that will help me with my problem. I have tried using the plotyy function but I am not sure if you can use this function with two left side axis line graphs and one right side graph. Here is code I have written so far in my attempt.
labels = ["Data 1"; "Data 2"; "Data 3"; "Data 4"; "Data 5"]
y1 = [137, 15, 2, 3, 37]
y2 = [43, 1, 67, 97, 41]
x = [1, 2, 3, 4, 5]
y3 = [0, .2, .3, .104, .09]
z1 = plot(x, y1, y2)
plot(x, y1, y2)
hold on
plot(x, y2)
xlabel("Version")
yyaxis left
ylabel("Y axis")
set(gca,'XTickLabel',labels)
yyaxis right
z = bar(x,y3)
z
yyaxis right
ylabel("Data")
While plotyy is the command to plot two normal plots using distinct left and right yaxes, I don't think you can do what you were trying to do with it. (i.e. mix two plots with a bar chart). However, what plotyy does is literally a simple case of overlaying two axes at the same position and making one 'see-through'. So you can use the same approach in general.
Here's your example above re-worked to achieve this (plus some extra bling):
x = [1, 2, 3, 4, 5]; labels = ["Data 1"; "Data 2"; "Data 3"; "Data 4"; "Data 5"];
y1 = [137, 15, 2, 3, 37]; y2 = [43, 1, 67, 97, 41]; y3 = [0, .2, .3, .104, .09];
ax_left = axes('position', [0.15, 0.12, 0.7, 0.82]); % manually positioned
plot (x, y1, 'r-', 'linewidth', 3); hold on
plot (x, y2, 'g:', 'linewidth', 3); hold off
set (ax_left, ...
'fontsize', 16, 'fontweight', 'bold', 'labelfontsizemultiplier', 1.2, ...
'color', 'none', ... % makes 'background' see-through
'box', 'off', ... % prevents left axis ticks in the right axis
'xlim', [0, 6], 'ylim', [0, 150], 'xtick', x, 'xticklabel', labels);
xlabel('Version'); ylabel('Left Y-Axis');
ax_right = axes('position', [0.15, 0.12, 0.7, 0.82]); % same position as above
bar (x, y3, 0.5, 'facecolor', [0, 0.5, 1]); % nice narrow light blue columns
set (ax_right, ...
'fontsize', 16, 'fontweight', 'bold', 'labelfontsizemultiplier', 1.2, ...
'yaxislocation', 'right', ...
'ycolor', [0, 0.5, 1], ... % same nice light blue color as bar chart
'box', 'off', 'xlim', [0, 6], 'ylim', [0, 0.35], 'xtick', []);
ylabel('Data');
% ensure axes are stacked in the order you want them to appear (bottom to top)
axes(ax_right);
axes(ax_left);

Octave: expecting scalar N, or 2-/4-element vector DOM-ezsurf Error

I need some kind of help about ezsurf
as I understand from my research matlab fplot is equal to ezplot in octave. And I write a script
fx = #(x,y) x.*sin(y);
fy = #(x,y) -x.*cos(y);
fz = #(x,y) y;
ezsurf(fx, fy, fz,[-5 5 -5 -2],'--','EdgeColor','g')
hold on
ezsurf(fx, fy, fz,[-5 5 -5 -2],'EdgeColor','none')
hold off
if I able to run the script I expect to see this image
However when I run the script I get this error
error: ezsurf: expecting scalar N, or 2-/4-element vector DOM
error: called from
__ezplot__ at line 260 column 7
ezsurf at line 78 column 19
file at line 4 column 1
What is the "expecting scalar N" what should I understand I how can I fix this.
Thank you so much in advance
fx = # (x,y) x .*sin(y);
fy = # (x,y) -x .*cos(y);
fz = # (x,y) y;
h1 = ezsurf (fx, fy, fz, [-5, 5, -5, -2]);
set (h1, 'edgecolor', 'g', 'linestyle', '--', 'linewidth', 0.1);
hold on
h2 = ezsurf (fx, fy, fz, [5, -5, 5, -2]);
set (h2, 'edgecolor', 'none');
hold off
colormap (parula (256)); % assuming you have the parula colormap installed

Automatic Level Generation from Array

So, I am trying to make the stages for the level in my game automatically generated.
I made an array (note, the amount of "tiles" on the screen is 16x16):
var background:Array=new Array(
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
)
And as you can probably tell, each 1 or 0 corresponds to if the tile is one thing or another (there or not there in this scenario).
I am pretty bad at the next part that I did.
I decided to make this using http://www.flashgametuts.com/tutorials/as3/how-to-create-a-platform-game-in-as3-part-2/'s method (kinda).
var bkgblocks:Sprite=new Sprite();
var bkgblocksw:Number=stage.stageWidth/16
var bkgblocksh:Number=stage.stageHeight/16
//the blocks are 45 pixels wide and tall
var row:int=0;
for(var i:int=0; i<background.length;i++){
if((i+1)/16==int((i+1)/16)){
//if i is divisible by 16
row++
}
if(background[i]==1){
bkgblocks.graphics.beginFill(0x000000)
bkgblocks.graphics.drawRect(I have no idea what to do here ,row*stage.stageHeight/16,bkgblocksw,bkgblocksh);
bkgblocks.graphics.endFill()
addChild(bkgblocks)
}
}
As you can see, I have no idea how or where to place the blocks!
I have where to place their y coordinate, but the x is way too confusing.
I thought I could do something like this
i*(45/(row+1))
but that messed up completely. This is more of a math question, I'm sorry, but if anybody can (or has) figure this out, I would appreciate it.
I usually prefer packing a grid into an array of arrays to make it more human-readable e. g.
var grid:Array = [
[0, 0, 1, 0, 0],
[0, 1, 0, 1, 0],
[1, 0, 0, 0, 1],
[0, 1, 0, 1, 0],
[0, 0, 1, 0, 0]
];
Where the first (outer) array contains rows of cells, each row represented by an array
So you can access a cell by calling grid[y][x] and find the 'real' coordinates by multiplying x and y by const CELL_SIZE
It seems you are tangled with 1D-2D coordinate transformation.
Let's width of your screen (2D coordinates) is Wdt. So element with (x,y) coordinates will be at y * Wdt + x index of 1D array.
A[y * Wdt + x] corresponds to Screen[y][x]
And back tranform:
x = index %% Wdt //integer modulus
y = index \ Wdt //integer division
Screen[index \ Wdt] [index %% Wdt] = A[index]