winforms chart, change values on x axis - winforms

I have added values on x axis between 0-255. I add the values to a serie with serie.addXY(127,10000); When the chart is displayed, the values it shows on the x axis are -1, 49, 99...
How can I change this to display 0, 50,100?

Try setting axis bounds. You can do that in the designer or via code:
Chart1.ChartAreas["Default"].AxisX.Minimum = 0;
Chart1.ChartAreas["Default"].AxisX.Maximum = 255;

Related

How to properly create outline around image using RGB values?

I have an image that I import into Octave 5.2, and I would like to create an outline all the way around the image array using RGB values.
I'm having trouble inserting the RGB values back into the array correctly, inserting / generating the two rows at top, two columns on the left, two columns on the right, and two rows on the bottom all the way around the image / converted double array.
Example of original image:
Example of the image I'm trying to get when done:
My logic was:
To convert the image to a double array so I can do math / insert the RGB values where I wanted them.
Insert the RGB values into the left, right, top, bottom of the array.
Convert the double array back to uint8 to export / view it as image.
My code so far:
pkg load image
img_fn=('https://i.imgur.com/KKxJaOy.png'); %original image
f=imread(img_fn);
[im_r im_c]=size(f);
size_min=min(im_r,im_c); %get minum size from row and col
f_double=double(f); %need to convert to double to do math functions on it
outline_left_of_box=repmat(255,[rows(f_double),2]); %Create left line array of outline red box
f_double_tmp_red(:,:,1)=[outline_left_of_box,f_double];%Create left line of outline red box
red_outline_right_of_box=repmat(255,[rows(f_double),2]); %Create right line array of outline red box
red_outline_top_of_box=repmat(255,[2,columns(f_double)]); %Create top line array of outline red box
red_outline_bottom_of_box=repmat(255,[2,columns(f_double)]); %Create bottom line array of outline red box
%convert back to image
red_outline_img=uint8(f_double);
imshow(red_outline_img); %used to show image in octave plot window
Please note: I'm converting the image array into a double because calculations will be done on the array to get the desired color box around the image, but I'm just trying to get the inserting RGB values into the array issue fixed first.
Maybe it's easier to simply paste the inner part of the input image onto some "background" image with the desired border color, like so:
pkg load image
% Read image, get dimensions, convert to double
f = imread('https://i.imgur.com/KKxJaOy.png');
[im_ro, im_co, im_ch] = size(f);
f_double = double(f);
% Set up width and color of border
bw = 2;
color = ones(1, 1, im_ch);
color(1, 1, :) = [255, 0, 0];
% Create image of same size as input with solid color, and paste inner part of input
red_outline_img = ones(im_ro, im_co, im_ch) .* color;
red_outline_img(bw+1:end-bw, bw+1:end-bw, :) = f_double(bw+1:end-bw, bw+1:end-bw, :);
red_outline_img = uint8(red_outline_img);
imshow(red_outline_img);
That'd be the output:
Another thing you could try is plot the lines as you suggest, which can be done very efficiently with some clever use of xlim/ylim, and then print the whole thing as an -RGBImage to get it back in image form.
The only caveat here though is that you will need to play with the formatting options to get what you're really after (e.g. in case you want higher or lower resolution), since you really are printing what's on your screen at this point.
E.g.
L = imread('leaf.png');
imshow(L)
hold on
plot( [xlim, fliplr(xlim);xlim, xlim], [ylim, ylim;fliplr(ylim), ylim], 'r', 'linewidth', 2 )
hold off
set( gca, 'position', [0, 0, 1, 1] );
set( gcf, 'paperposition', [0, 0, 1, 1] );
R = print( '-RGBImage' );
close
imshow(R); set( gcf, 'color', 'k'); axis off

How to make DrawString work for negative y scale factor?

Working on a private stock chart where I use a rendering rectangle with an origin at lower left and inverted y axis, scale factor y is negative. Y axis ticks render nicely but drawing text (drawstring) is where I run into problems.
using (Pen pen = new Pen(_color))
using (Font drawFont = new Font("Arial", 16))
using (SolidBrush drawBrush = new SolidBrush(Color.Black))
{
pen.Width = 1F / e.Graphics.DpiX;
foreach (float tick in this.TimeSeriesPanelControl.YTicks)
{
e.Graphics.DrawLine(pen, right, tick, right + 10, tick);
// this is not producing text to the right of the tick that renders properly.
e.Graphics.DrawString(tick.ToString("F2"), drawFont, drawBrush, right + 15, tick);
}
}
I have seen that the text is upside down caused by the negative scale factor on the y coordinate.
The question is how to make drawstring render the text to the right of the tick?

how to plot 2D intensity plot in matplotlib?

I have an Nx3 array which stores the values in N coordinates. The first and second column correspond to x and y coordinate respectively, and the third column represents the value at that coordinates. I want to plot a 2D intensity plot, what's the best way to do it?
If the coordinates are evenly spaced, then I can use meshgrid and then use imshow, but in my data the coordinates are not evenly spaced. Besides, the array is very large N~100000, and the values (third column) span several orders of magnitude (so I should be using a logplot?). What's the best way to plot such a graph?
You can use griddata to interpolate your data at all 100000 points to a uniform grid (say 100 x 100) and then plot everything with a Log scaling of the colours,
x = data[:,0]
y = data[:,1]
z = data[:,2]
# define grid.
xi = np.linspace(np.min(x),np.max(x),100)
yi = np.linspace(np.min(y),np.max(y),100)
# grid the data.
zi = griddata(x,y,z,xi,yi,interp='linear')
#pcolormesh of interpolated uniform grid with log colormap
plt.pcolormesh(xi,yi,zi,norm=matplotlib.colors.LogNorm())
plt.colormap()
plt.show()
I've not tested this but basic idea should be correct. This has the advantage that you don't need to know your original (large) dataset and can work simply with the grid data xi, yi and zi.
The alternative is to colour a scatterplot,
plt.scatter(x, y, c=z,edgecolors='none', norm=matplotlib.colors.LogNorm())
and turn off the outer edges of the points so they make up a continuous picture.

Highcharts - How to specify dimensions of rectangles

I working with highcharts in angularjs and I want to change the background like in the picture. Also, I want to be able to specify dimentions of rectangles
UPDATE
The problem is when I give the parameters to draw my rectangles, it's affecting all the div and what I want is to draw the rectangles on my chart surface only. The problem is because of "this" which I'm using in my code and I want now to replace it with chart.
You can use the renderer to draw arbritary squares on a chart. You can also use the Axis function toPixels to convert values to pixels. I have a function that takes x and y values and draws a square. If you butted those squares together you could have your regions.
var drawSquare = function(x1,x2,y1,y2,color) {
x1 = chart.xAxis[0].toPixels(x1);
x2 = chart.xAxis[0].toPixels(x2);
y1 = chart.yAxis[0].toPixels(y1);
y2 = chart.yAxis[0].toPixels(y2);
var width = x2 - x1;
var height = y1 - y2;
chart.renderer.rect(x1,y2,width, height, 0)
.attr({
fill: color,
zIndex: 0
})
.add();
};
drawSquare(0,40,0,35,'rgba(129,184,222,.5)');
drawSquare(40,100,0,35,'rgba(255,223,134,.5)');
drawSquare(0,40,35,150,'rgba(130,215,169,.5)');
drawSquare(40,100,35,150,'rgba(183,153,206,.5)');
http://jsfiddle.net/Lh74L8vu/1/

How to interpolate a HSV color?

I am creating an application in win32 api, which will use a progress bar. This progress bar, should change its color. From red (left end) to green(right), and in the middle some yellow.
I searched a little, and found out, that I should use HSV to achieve this. I just don't know how? I found in this link, two functions, to convert the color, from RGB to HSV and back.
But what should I do if the color has been converted to HSV?
Like RGB coordinates, HSV coordinates define a point in a three dimensional space.
You may find a trajectory form one point (x0, one color) to the second (x1) with a formula like:
x = x0 + alpha * (x1-x0)
with alpha varying form 0.0 to 1.0
You can do this for all three components simultaneaously.
With a trajectory from green to red in HSV space you will mainly modify the H (Hue) value. If you want to see some yellow in the middle of your path (and not violett) you need to define a second or even third color and walk
green -> yellow -> red
Edit: Example
int hue0 = 0; // red
int hue2 = 120; // green
// find 100 colors between red and green
for(double alpha = 0; alpha <= 1.0; alpha += 0.01)
{
hueX = hue0 + alpha * (hue1 - hue0);
// same for value, saturation:
// valX = val0 + alpha * (val1 - val0)
// ...
// plot this color
}

Resources