Specify aspect ratio / equal scales on Vegalite plot - d3.js

On an Vegalite xy chart, how do I specify the data aspect ratio to 1? In other words, I want the same scaling from data to plot units for both x and y axes. In Matplotlib this is achieved with matplotlib.axes.Axes.set_aspect('equal'). How would I modify the following spec snippet?
{
"width": 500,
"height": 500
"mark": {"type": "line", "point": {"size": 0}},
"encoding": {
"x": {"field": "y", "type": "quantitative"},
"y": {"field": "x", "type": "quantitative"},
"color": {
"field": "run",
"type": "nominal",
"scale": {"scheme": "magma"}
}
}
}

Vega-lite and altair don't have an aspect argument or set_aspect method like in matplotlib. I had a same question earlier this week and this is the answer that I got from one of the devs;
It’s definitely possible to change the width/height of a figure, which
is almost the same thing See
https://altair-viz.github.io/gallery/aggregate_bar_chart.html for an
example
So as long as your width and height have the same value then by default the aspect will also be equal.

Related

How to do multiple rotations without losing a degree of freedom?

I'm trying to display multiple "3d lines" imported from an XML file. I simply need to draw simple rectangular boxes using the provided parameters (5 x 5 x "length"), move it at the right position and rotate it using the provided rotations (in degree) - the expected result is multiple shapes starting at the provided position with their length continuing in an orientation that match the provided rotation.
For some shapes, two of the rotation axes are doing the exact same thing - this appear to be a gimbal lock issue (probably amplified because most of the rotations here are at 90 degrees).
I searched and tried multiple solutions for hours, notably using a 4x4 matrix instead of my initial implementation using geometry.rotateX/rotateY/rotateZ. Unfortunately, I'm unable to find a working solution... I found people mentioning quaternions, but I'm not quite sure how to apply this to my current use case...
I'm sure there is a (relatively) easy solution for my issue, but right now, I'm unable to find it... I'm open to any way of doing it, as long as it can be done with the input I have...
Can anyone push me in the right direction?
Thank you so much for your help.
For reference, I'm currently using r124. Here's a simplified example of my parsed input :
var lines = [
{
"length": "150",
"position": {
"x": "100",
"y": "-10",
"z": "1800"
},
"rotation": {
"x": "90",
"y": "0",
"z": "0"
}
},
{
"length": "325",
"position": {
"x": "100",
"y": "-10",
"z": "1800"
},
"rotation": {
"x": "-90",
"y": "-90",
"z": "-90"
}
},
{
"length": "55",
"position": {
"x": "100",
"y": "-10",
"z": "1800"
},
"rotation": {
"x": "0",
"y": "0",
"z": "-90"
}
}
]

How can i create thumbnails with image, with coord X-0, Y-0

Voyager creates a crop on from the center, and I need to crop the beginning of the image. How do I do this? Only the width and height of the crop are specified in the documentation.
"name": "cropped",
"crop": {
"width": "300",
"height": "250"
}
Right in there documentation about cropping it shows
"thumbnails": [
{
"type": "crop",
"name": "crop-500-500",
"width": 500, // Required
"height": 500, // Required
"x": 50, // Optional. Left offset
"y": 50, // Optional. Top offset
}
]

Cannot get ui_guage to display each message after specified delay time

My experiment is to change the ui_guage according to the numbers from a csv file. Each number is delayed for 5 sec.(code at end)
Input to csv file is a multi-line msg.payload with three values per line.i.e,
name1, numerical1,numerical11
name2 numerical2,numerical22, etc
problem: i get no delay of 5sec per message on the gauge...it directly shows the final value present in the last column (i have used a delay node also but still...)
example: display column 3 numericals as indicator with 5 sec delay on gauge.
gauge output: numerical22 (the indicator sets to this position at once)
So, the required per message delay (5 sec) is absent.
I require the delay.
I'am working on IBM cloud lite plan, node red v1.0.6
please review the following code
any help is welcome
if similar is answered before please re-direct me the solution.
To run following code:
open Node-RED
Click the three lines (top right)
import
Copy & paste the following flow json code and click "import" button
know more : Importing and Exporting Flows in Node-RED
The code:
[
{
"id": "c9b43c3a.da2e4",
"type": "ui_gauge",
"z": "ac0d0d22.69ebb",
"name": "",
"group": "c604d450.9712c8",
"order": 13,
"width": "5",
"height": "5",
"gtype": "gage",
"title": "<img height=\"50\" width=\"50\" src=\"https://upload.wikimedia.org/wikipedia/commons/b/bf/Pressure_gauge.svg\"/>",
"label": "units",
"format": " {{msg.payload.col3}}",
"min": 0,
"max": 10,
"colors": [
"#00b500",
"#e6e600",
"#ca3838"
],
"seg1": "",
"seg2": "",
"x": 840,
"y": 320,
"wires": []
},
{
"id": "c604d450.9712c8",
"type": "ui_group",
"z": "",
"name": "tab1",
"tab": "c733c61c.6e4828",
"order": 1,
"disp": true,
"width": "12",
"collapse": false
},
{
"id": "c733c61c.6e4828",
"type": "ui_tab",
"z": "",
"name": "Home1",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]

Vega-lite bar chart space between bars

D3 newbie.
How I adjust the spacing between bars in vega-lite bar chart and override the default? binSpacing I think only works on histograms. See code below.
I'll want to adjust colour of text and font family too... But am having trouble finding it in the docs.
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"width": 1200,
"height": 900,
"data": {
"url": "data/seattle-weather.csv"
},
"mark": "bar",
"encoding": {
"x": {
"aggregate": "count",
"type": "quantitative"
},
"size": {
"value": 40
},
"y": {
"field": "date",
"type": "temporal",
"timeUnit": "month",
"axis": {
"title": "Regions"
}
},
"color": {
"field": "weather",
"type": "nominal",
"scale": {
"domain": [
"0-20 days",
"21-27 days",
">28 days"
],
"range": [
"red",
"orange",
"green"
]
},
"legend": {
"title": "Case Ageing"
}
}
}
}
I can understand your confusion. It seems there are three questions:
How do I change bin width for histograms? This is documented here. If you have trouble with a reproducible example, I will be happy to help.
How do I adjust the spacing of the bars? This is controlled by padding, paddingInner and paddingOuter all documented at the encoding level and at the config level. You might be having trouble since you are setting size manually with "size": {"value": 40}, but I am guessing this is a remnant from experimenting. Here is a working spec from this gist. You can play with paddingOuter, paddingInner, or add padding to apply to both inner and outer.
How do I change font styling? See this gist.

kartograph svg map is empty when using "polygons" bounds mode

I 'm trying to generate svg maps from the GEOFLA shapefiles.
Using 'bbox' bounds mode with manually setting the bbox values works well :
{
"layers": [{
"id": "depts",
"src": "data/DEPARTEMENTS/DEPARTEMENT.shp",
"filter": {"CODE_REG": "24"},
"simplify": {
"method": "distance",
"tolerance": 8
},
"attributes": "all"
}],
"bounds": {
"mode": "bbox",
"data": [-4.5, 42, 8, 48],
},
"export": {
"width": 600,
"ratio": 0.8
}
}
But when setting the bounds mode to 'polygons', then i get an empty svg map :
{
"layers": [{
"id": "depts",
"src": "data/DEPARTEMENTS/DEPARTEMENT.shp",
"filter": {"CODE_REG": "24"},
"simplify": {
"method": "distance",
"tolerance": 8
},
"attributes": "all"
}],
"bounds": {
"mode": "polygons",
"data": {
"layer": "depts"
},
"padding": 0.06
},
"export": {
"width": 600,
"ratio": 0.8
}
}
I had a look in kartograph files and i noticed that the "get_features" method in "map.py" return a Polygon which coordinates doesn't intersect with the features geometry previouly extracted from the shapefile.
Then, each feature are throw away in the "get_features" method of the "maplayer.py" file when checking if feature geometry intersects with the "layer.map.view_poly" property.
I had a similar problem using GEOFLA file projection.
The solution I've found is basically to change my shapefile projection using QGIS. My idea was to use the projection of the shapefile given in installation guide which worked for me.
Get example shape file from kartograph installation page
Load this vector layer in QGIS Add your GEOFLASH layer in QGIS
Right-click on GEOFLASH layer and "Save as..." menu
In the save window, give a new name for your layer (eg : DEPARTEMENT_WGS84.shp)
Click CSR button and select the test layer projection (WGS 84 / EPSG:4326)
Click OK
Check the new shape file has correct projection :
cat DEPARTEMENT_WGS84.prj
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Now your script should work fine using new shape file.

Resources