How to rotated left axis label in stack bar charts? - swift

I am using Charts library. I want to rotate left axis label to 90 degrees. How can I do that? Please help me.
I am able to rotate xAxis label. This is how I rotate xAxis:
barChart.xAxis.labelPosition = XAxis.LabelPosition.topInside
barChart.xAxis.labelRotationAngle = kXAxisLabelRotationAngleForShareOfVoiceByDrugs
And for leftAxis:
barChart.leftAxis.valueFormatter = IndexAxisValueFormatter(values:hotTopicsAndWeakSignalsModel.barChartDrugNames)
barChart.leftAxis.labelPosition = .outsideChartr
How can set rotation to leftAxis?

To rotate the xAxis Label, you need to do this:
barChart.xAxis.labelRotationAngle = YOUR_ANGLE
like
barChart.xAxis.labelRotationAngle = 90.0

Related

Manually write world file (jgw) from Leaflet.js map

I have the need to export georeferenced images from Leaflet.js on the client side. Exporting an image from Leaflet is not a problem as there are plenty of existing plugins for this, but I'd like to include a world file with the export so the resulting image can be read into GIS software. I have a working script fort his, but I can't seem to nail down the correct parameters for my world file such that the resulting georeferenced image is located exactly correctly.
Here's my current script
// map is a Leaflet map object
let bounds = map.getBounds(); // Leaflet LatLngBounds
let topLeft = bounds.getNorthWest();
let bottomRight = bounds.getSouthEast();
let width_deg = bottomRight.lng - topLeft.lng;
let height_deg = topLeft.lat - bottomRight.lat;
let width_px = $(map._container).width() // Width of the map in px
let height_px = $(map._container).height() // Height of the map in px
let scaleX = width_deg / width_px;
let scaleY = height_deg / height_px;
let jgwText = `${scaleX}
0
0
-${scaleY}
${topLeft.lng}
${topLeft.lat}`
This seems to work well at large scales (ie zoomed in to city-level or so), but at smaller scales there is some distortion along the y-axis. One thing I noticed is that all examples of world files I can find (and those produced from QGIS or ArcMap) all have the x-scale and y-scale parameters being exactly equal (oppositely signed). In my calculations, these terms are different unless you are sitting right on the equator.
Example world file produced from QGIS
0.08984380916303301 // x-scale (size of px in x direction)
0 // rotation parameter 1
0 // rotation parameter 2
-0.08984380916303301 // y-scale (size of px in y direction)
-130.8723208723141056 // x-coord of top left px
51.73651369984968085 // y-coord of top left px
Example world file produced from my calcs
0.021972656250000017
0
0
-0.015362443783773333
-130.91308593750003
51.781435604431195
Example of produced image using my calcs with correct state boundaries overlaid:
Does anyone have any idea what I'm doing wrong here?
Problem was solved by using EPSG:3857 for the worldfile, and ensuring the width and height of the map bounds was also measured in this coordinate system. I had tried using EPSG:3857 for the worldfile, but measured the width and height of the map bounds using Leaflet's L.map.distance() function. To solve the problem, I instead projected corner points of the map bounds to EPSG:3857 using L.CRS.EPSG3857.project(), the simply subtracted the X,Y values.
Corrected code is shown below, where map is a Leaflet map object (L.map)
// Get map bounds and corner points in 4326
let bounds = map.getBounds();
let topLeft = bounds.getNorthWest();
let bottomRight = bounds.getSouthEast();
let topRight = bounds.getNorthEast();
// get width and height in px of the map container
let width_px = $(map._container).width()
let height_px = $(map._container).height()
// project corner points to 3857
let topLeft_3857 = L.CRS.EPSG3857.project(topLeft)
let topRight_3857 = L.CRS.EPSG3857.project(topRight)
let bottomRight_3857 = L.CRS.EPSG3857.project(bottomRight)
// calculate width and height in meters using epsg:3857
let width_m = topRight_3857.x - topLeft_3857.x
let height_m = topRight_3857.y - bottomRight_3857.y
// calculate the scale in x and y directions in meters (this is the width and height of a single pixel in the output image)
let scaleX_m = width_m / width_px
let scaleY_m = height_m / height_px
// worldfiles need the CENTRE of the top left px, what we currently have is the TOPLEFT point of the px.
// Adjust by subtracting half a pixel width and height from the x,y
let topLeftCenterPxX = topLeft_3857.x - (scaleX / 2)
let topLeftCenterPxY = topLeft_3857.y - (scaleY / 2)
// format the text of the worldfile
let jgwText = `
${scaleX_m}
0
0
-${scaleY_m}
${topLeftCenterPxX}
${topLeftCenterPxY}
`
For anyone else with this problem, you'll know things are correct when your scale-x and scale-y values are exactly equal (but oppositely signed)!
Thanks #IvanSanchez for pointing me in the right direction :)

Change origin position in ios-charts

Has anyone tried setting a custom origin (0,0) for ios-charts?
The default origin is at the bottom left corner, I want my origin at the top left corner, is this possible? (see images for reference)
default
what i want to achieve
You can change label position for XAxis instance object using your chartView object.
//self.chartView is the ChartView instance.
let xAxis : XAxis = self.chartView.xAxis
xAxis.labelPosition = .top
It's quite simple.
First, as another answer said, change xAxis.labelPosition = .top.
Then, set Y axis self.chartView.leftAxis.inverted = true.
That`s all!

How do I add a units label to a ILNumerics Colorbar

I would like to display the units in text for the values displayed on the colorbar. I have a colorbar added to my ILSurface and I'd like to show my units in text on the color bar along with the range.
Edit: I want to display text at the bottom of the color bar below the bottom tick just the one label.
I was able to get this to work this way
new ILColorbar()
{
Children = { new ILLabel("nm") {Position = new Vector3(.2f,.98f,0) } }
}
I have to say the Position coordinates are not very intuitive. I had to basically adjust the numbers by trial and error until it fit. I knew that the values range 0..1 so the X value was 1 at the bottom but I wanted it up from the border. And the Y value would need to be indented in some but I wasn't sure what was a good value but .2 works.
You can access the axis of ILColorbar and configure it in the usual way. Use the LabelTransformFunc on the ticks to set your own label text. You can use the default transform func and add your unit string.
Example:
var cb = scene.First<ILColorbar>();
cb.Axis.Ticks.LabelTransformFunc = (ind, val) =>
{
return ILTickCollection.DefaultLabelTransformFunc(ind, val) + "nm";
};
You can read more about the axis configuration here:
Axis Configuration
LabelTransformFunc in ApiDoc
Edit:
If only one label is needed, then add a new ILLabel object in ILColorbar group as follows:
new ILColorbar() {
new ILLabel("z(nm)") {
Position = new Vector3(0.5,1,0),
Anchor = new PointF(0.5f,0)
}
}
The ILColorbar area have the relative coordinates 0..1 over the width and the height of the color bar. So we set position x in the middle of the ILColorbar, and position y at the bottom.
The Anchor position is used as relative position in relation to the Position point.
ILLabel Documentation

How to rotate an image 45 degrees twice in matlab and keep the same size at the end?

I want to :
rotate an image (size 512x512) with 45 degrees.
make some processing on it.
rotate the image with -45 degrees.
my problem is when i apply rotation with 45 degrees and -45 degrees, the size of the image changes and i want it to be the same.
The usual procedure to rotate images is to scale the image up, rotate the image and scale it down. This way, you can avoid the dark margins that will appear when you rotate.
Matlab does this process automatically. So if you want a particular dimension for the image, you have to choose the appropriate region of the image after you have rotated it.
Suppose we wanted to rotate the image and want to retain the same dimensions as the original image, we can do this:
img = imread('image.png');
r = numel(img(:,1));
c = numel(img(:,2));
nimg = imrotate(img, 45);
nimg = imrotate(nimg, 45);
n_R = numel(nimg(:,1));
n_C = numel(nimg(:,2));
n_R = n_R+mod(n_R, 2); %to avoid dimensions being in double datatype
n_C = n_C+mod(n_C, 2);
oimg = nimg(((n_R/2)-(r/2)):((n_R/2)+(r/2)), ((n_C/2)-(c/2)):((n_C/2)+(c/2)),:);
imwrite(oimg, 'rot_image.png');
You can't do it. It doesn't make sense. Simple experiment:
get a square piece a paper and hold it against a white wall
draw the borders of the square on the wall
rotate the piece of paper 45 degrees
draw another square on the wall that encloses the rotated piece of paper
take the piece of paper out of the wall and observe why you can't do that
leave the marks on the wall so you don't forget

iPhone sdk: Core-plot How to display y Axis on the right side on

iPhone sdk: Core-plot How to display y Axis on the right side on??
I am now using Core-plot in iphone sdk ,
This is what i have done so far
but i want to put the Yaxis in right hand side.
i have enable the allowsuserInteractive
**plotSpace.allowsUserInteraction=NO;
volumePlotSpace.allowsUserInteraction=YES;**
But i want X axis and Y axis always stay the right hand side and bottom,
Whatever user scale big or small....
like this:
Which version of Core-Plot are you using?
Core-Plot 0.9 allows you to set constraints on axes positions. A code line like this should do the job:
// 'graph' is your CPTXYGraph object
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
// move axis to the rightmost position
axisSet.yAxis.axisConstraints = [CPTConstraints constraintWithUpperOffset:0];
// put ticks on the right hand side of the axis
axisSet.yAxis.tickDirection = CPTSignPositive;
// add some padding to the right so that labels are actually visible
graph.plotAreaFrame.paddingRight = 20.0f;
I'm not aware in which version this was introduced, but at least for Core-Plot 0.2.2 the procedure was a bit different. I don't have it on my box now so I can't check, but this is how to fix Y axis on the left hand side:
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
axisSet.yAxis.isFloatingAxis = YES;
// fixed lower constraint, no upper constraint
CPConstraints yConstraints = {CPConstraintFixed, CPConstraintNone};
axisSet.yAxis.constraints = yConstraints;
I guess that for right hand side yConstraints should be {CPConstraintNone, CPConstraintFixed}.
In coreplot 1.5.1 , you can use CPTConstraints to set the Y axis on left or right, OR , set the X axis on bottom or top
yAxis.axisConstraints = CPTConstraints(lowerOffset: CGFloat(0.0))
lowerOffset means left(Y axis) or bottom(X axis);
upperOffset means right(Y axis) or top(X axis)