Graph-ET x-axis labels - smalltalk

I drew a bar diagram for my benchmarks in Graph-ET on Pharo. Does anybody
know how to add the labels to x-axis? I want to write the name of the benchmark under the each of bars.

Open a workspace, and type the following:
| chart |
chart := GETDiagramBuilder new.
chart verticalBarDiagram
models: ($a to: $z);
y: #asInteger;
regularAxis;
height: 200.
chart open.
"We use the same model elements"
($a to: $z) do: [ :value |
| bar label |
"We define a label, and add it to the view"
label := ROLabel elementOn: value asString.
chart rawView add: label.
"We get the bar, the gray element that grows up"
bar := chart rawView elementFromModel: value.
"Move the label below its corresponding bar"
ROConstraint move: label below: bar ].
"Inserting high level labels"
chart rawView add: ((ROLabel red elementOn: 'Chart about my life') translateBy: 200 # 0).
chart rawView add: ((ROLabel elementOn: 'Happiness') translateBy: -30 # -40).
chart rawView add: ((ROLabel elementOn: 'Passing days') translateBy: 650 # 210)

In GraphET2 (which uses Roassal2) building charts like the one you wanted is way easier!
| chart |
chart := GET2Bar data: ($a to: $z).
chart
y: #asInteger;
title: 'Chart about my life';
titleColor: Color red.
chart yAxis title: 'Happiness'.
chart xAxis addModelLabels:[:v | |s| s:= v asString. s,s,s,s. ];
verticalLabelsInverted;
title: 'Passing days'.
chart open.
Check it out here!
I hope it helps :)

Related

Color Palette reverses: Assigning specific color to one cluster and a different color to another cluster in KMeans. (GEE - PythonAPI)

I am trying to cluster the image using GEE API into 2 classes and the algorithm is working fine but when I am visualizing, the colors reverse. That is, for year1 -> class1: green, class2: yellow but for year2 the colors revert for the same lines of code. Year2 -> class1: yellow, class2: green.
Code:
def kmeans(year):
training = year.sample(**{
'region': country,
'scale': 30,
'numPixels': 5000
})
#Instantiate the clusterer and train it.
clusterer = ee.Clusterer.wekaKMeans(2).train(training)
#Cluster the input using the trained clusterer.
result = year.cluster(clusterer)
return result
###VISUALIZATION
def vis_kmeans(previous_year, next_year):
Map = geemap.Map()
#Display the clusters with random colors.
kmeansVis = {'min':-1, 'max':1, 'palette':['green', 'yellow']}
Map.addLayer(previous_year, kmeansVis, 'year1')
Map.addLayer(next_year, kmeansVis, 'year2')
Map.centerObject(country, 10) #to adjust the zoom center
return Map
Output Year1:
Output Year2:
Why are the colors reverting? How do I avoid it?

PyQGIS 3.18.2 Removing Band Name from Symbology

I recently updated my QGIS and I noticed the styles now show the band Band 1(Gray)
The issue is it now shows within my print layout:
Using PYQGIS, how can I remove just the Band 1 (Gray)?
For reference, here is how I am currently setting the legend in the layout:
def set_legend(layout: QgsPrintLayout, tree: QgsLayerTree, layer: QgsLayer, item_id: str):
'''Sets the Legend items'''
logging.info(f'setting legend: {item_id}')
item = layout.itemById(item_id)
# set layer as root for legend
tree.addLayer(layer)
item.model().setRootGroup(tree)
node = item.model().rootGroup().findLayer(layer)
# hide the node title
QgsLegendRenderer.setNodeLegendStyle(node, QgsLegendStyle.Hidden)
Thank you!
Here's my solution after digging StackOverflow and the API:
root = model.rootGroup().findLayer(layer)
# hide the node with label: Band 1 (Gray)
if isinstance(layer, QgsRasterLayer):
nodes = model.layerLegendNodes(root)
if nodes[0].data(0) == 'Band 1 (Gray)':
indexes = list(range(1, len(nodes)))
QgsMapLayerLegendUtils.setLegendNodeOrder(root, indexes)
model.refreshLayerLegend(root)

how to draw lines in Pine script (Tradingview)?

Pine editor still does not have built-in functions to plot lines (such as support lines, trend lines).
I could not find any direct or indirect method to draw lines.
I want to build function that look like below (for example only)
draw_line(price1, time1,price2, time2)
any Ideas or suggestions ?
Unfortunately I don't think this is something they want to provide. Noticing several promising posts from 4 years ago that never came through. The only other way, seem to involve some calculations, by approximating your line with some line plots, where you hide the non-relevant parts.
For example:
...
c = close >= open ? lime : red
plot(close, color = c)
would produce something like this:
Then, you could try to replace red with na to get only the green parts.
Example 2
I've done some more experiments. Apparently Pine is so crippled you can't even put a plot in function, so the only way seem to be to use the point slope formula for a line, like this:
//#version=3
study(title="Simple Line", shorttitle='AB', overlay=true)
P1x = input(5744)
P1y = input(1.2727)
P2x = input(5774)
P2y = input(1.2628)
plot(n, color=na, style=line) // hidden plot to show the bar number in indicator
// point slope
m = - (P2y - P1y) / (P2x - P1x)
// plot range
AB = n < P1x or n > P2x ? na : P1y - m*(n - P1x)
LA = (n == P1x) ? P1y : na
LB = (n == P2x) ? P2y : na
plot(AB, title="AB", color=#ff00ff, linewidth=1, style=line, transp=0)
plotshape(LA, title='A', location=location.absolute, color=silver, transp=0, text='A', textcolor=black, style=shape.labeldown)
plotshape(LB, title='B', location=location.absolute, color=silver, transp=0, text='B', textcolor=black, style=shape.labelup )
The result is quite nice, but too inconvenient to use.
UPDATE: 2019-10-01
Apparently they have added some new line functionality to Pinescript 4.0+.
Here is an example of using the new vline() function:
//#version=4
study("vline() Function for Pine Script v4.0+", overlay=true)
vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line, 54 lines maximum allowable per indicator
return = line.new(BarIndex, -1000, BarIndex, 1000, xloc.bar_index, extend.both, Color, LineStyle, LineWidth)
if(bar_index%10==0.0)
vline(bar_index, #FF8000ff, line.style_solid, 1) // Variable assignment not required
As for the other "new" line function, I have not tested it yet.
This is now possible in Pine Script v4:
//#version=4
study("Line", overlay=true)
l = line.new(bar_index, high, bar_index[10], low[10], width = 4)
line.delete(l[1])
Here is a vertical line function by midtownsk8rguy on TradingView:
vline(BarIndex, Color, LineStyle, LineWidth) => // Verticle Line Function, ≈50-54 lines maximum allowable per indicator
// return = line.new(BarIndex, 0.0, BarIndex, 100.0, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=false) and RSI, Stochastic, etc...
// return = line.new(BarIndex, -1.0, BarIndex, 1.0, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=false) and +/-1.0 oscillators
return = line.new(BarIndex, low - tr, BarIndex, high + tr, xloc.bar_index, extend.both, Color, LineStyle, LineWidth) // Suitable for study(overlay=true)
if(bar_index%10==0.0) // Generically plots a line every 10 bars
vline(bar_index, #FF8000ff, line.style_solid, 1) // Variable assignment not required
You can also use if barstate.islast if you only draw your lines once instead of on each candle, this way you don't need to delete the previous lines.
More compact code for draw lines:
//#version=3
study("Draw line", overlay=true)
plot(n, color=na, style=line)
AB(x1,x2,y1,y2) => n < x1 or n > x2 ? na : y1 + (y2 - y1) / (x2 - x1) * (n - x1)
plot(AB(10065,10136,3819,3893), color=#ff00ff, linewidth=1, style=line,
transp=0)
plot(AB(10091,10136,3966.5,3931), color=#ff00ff, linewidth=1, style=line,
transp=0)
Here is an example that might answer the original question:
//#version=4
study(title="trendline example aapl", overlay=true)
//#AAPL
line12= line.new(x1=int(1656322200000),
y1=float(143.49),
x2=int(1659519000000),
y2=float(166.59),
extend=extend.right,
xloc=xloc.bar_time)
(to calculate the time it needs to be calculated as the *bar open time in unix milliseconds see: https://currentmillis.com/ ; can be calculated in excel with this formula =
= (([date eg mm/dd/yyyy]+[bar open time eg 9.30am])- 0/24 - DATE(1970,1,1)) * 86400000
= ((6/27/2022+9:30:00 AM)- 0/24 - DATE(1970,1,1)) * 86400000
= ((44739+0.395833333333333)- 0/24 - DATE(1970,1,1)) * 86400000
= 1656322200000
)
adjust the zero/24 to offset the time zone if needed eg 1/24

Setting a max axis value or range step for a Morris Bar Chart?

I was wondering if it is possible to set a max axis value (say, I want the highest point of my data to be the top end of the y-axis) on a bar chart? I see there are options for ymin and ymax on line charts but I can't seem to find any information about the bar charts.
Also, it would be helpful if anyone knew how to force the range between axis lanes to be a certain amount (say step up by 250 each line instead of the generated amount which in my case is too high for my liking).
Set a maximum value for the y axis
You can, indeed, set the ymax for bar charts also (even though this is not documented).
Morris.Bar({
element: 'bar-example',
data: [
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: 40 },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 }
],
xkey: 'y',
ymax: 300, // set this value according to your liking
ykeys: ['a', 'b'],
labels: ['Series A', 'Series B']
});
And have your y axis set to this maximum value:
Set a range value for the y axis
It seems that it's not possible to set a range value for the y axis. This value appears to be computed according to the values of the data passed to Morris.Bar.
Not documented, but you can set maximum y by applying ymax. You can manipulate the range by setting numLines (also not documented).
E.g.
var chart = new Morris.Bar({
...
ymin: 0,
ymax: 7,
numLines: 8,
...
});
The above defined chart will display values from 0 to 7 and display a grid line for each integer between 0 and 7 (therefore 8 as a parameter)
To change to ymax call this
chart.options["ymax"] = 300;
Where chart is your chart variable
I want the highest point of my data to be the top end of the y-axis
The documentation is very sparse and confusing but this is possible using the ymin variable which is only documented in the Lines & Area Charts. The default value for that variable seems to be auto 0 and changing it to just auto seems to produce the desired result as you can see below.
how to force the range between axis lanes to be a certain amount
This does not seem to be possible, natively. However, you can kind of hack the axis label with the following function. It will round the value to multiples of 250 BUT the grid lines won't be at the number shown. E.g. say a grid line is at 570. The function below will change the label to 500 but the line will still show at 570 mark.
yLabelFormat: function(d) {
return Math.round(d) - (Math.round(d) % 250);
},
As others have mentioned, you can set ymax to a value that you want your upper bound to be but since you want the highest data point to be the upper bound, set ymax to auto. You can also try changing numLines to different values for a better aesthetic.

Is it possible to get anti-alias for Font in Rebol Graphics VID?

Anti-alias works for Draw but I can't see how to get anti-alias for font : is it possible anywhow (including hacking rebol vid ...) because font in the picture generated below is not nice:
(source: reboltutorial.com)
view layout [
box 278x185 effect [ ; default box face size is 100x100
draw [
anti-alias on
; information for the next draw element (not required)
line-width 2.5 ; number of pixels in width of the border
pen black ; color of the edge of the next draw element
fill-pen radial 100x50 5 55 5 10 10 71.0.6 30.10.10 71.0.6
; the draw element
box ; another box drawn as an effect
15 ; size of rounding in pixels
0x0 ; upper left corner
278x170 ; lower right corner
]
]
pad 30x-150
Text "Experiment" font [name: "Impact" size: 24 color: white]
image http://www.rebol.com/graphics/reb-logo.gif
]
You want to use AGG fonts ...
http://www.compkarori.com/vanilla/display/AGG
In Windows, you just use the font name.