How do I set relative bar width in altair? - altair

How do I use relative bar width with altair? According to vega-lite documentation. This code:
{
"data": {"url": "data/seattle-weather.csv"},
"mark": {"type": "bar", "width": {"band": 0.7}},
"encoding": {
"x": {
"timeUnit": "month",
"field": "date"
},
"y": {
"aggregate": "mean",
"field": "precipitation"
}
}
}
produces a bar that occupies 70% of each x band.
How do I set this in altair? If I use something like:
.mark_bar(width={'band':0.7})
I got an error about width not being a number.
How do I set relative bar widths in altair?

You could also set the padding between the bars instead, using padding in the scale argument of the encoding field. For mark_bar, for example, setting it to 0.3, would set the bar width to 70% of the 'tick space'.
import altair as alt
from vega_datasets import data
source = data.seattle_weather()
alt.Chart(source).mark_bar().encode(
x=alt.X('month(date):O', scale=alt.Scale(padding=0.3)),
y='mean(precipitation):Q'
)

On the current development version of Altair on GitHub, what you suggested should work. As per this post, you should also be able to do the following:
import altair as alt
from vega_datasets import data
source = data.seattle_weather()
alt.Chart(source).mark_bar(
width=alt.RelativeBandSize(0.7)
).encode(
x='month(date):O',
y='mean(precipitation):Q'
)

Related

How to reduce size of customized scroll bar in Sublime Text 3

I have customized my scroll bar by referencing one answer from stackoverflow.
This is my Material-Theme-Darker.sublime-theme file
[
// More visible scrollbar
{
"class": "puck_control",
"layer0.texture": "User/theme_override/scroll_puck.png",
// Optional: set to your desired RGB color
"layer0.tint": [141, 234, 255],
"layer0.opacity": 1.0,
"layer1.opacity": 0.0,
"layer0.inner_margin": 2,
},
{
"class": "puck_control",
"attributes": ["horizontal"],
"layer0.texture": "User/theme_override/scroll_puck_horiz.png",
}
]
But the scroll bar is quite bold and I want it to be short in width so can anyone tell me how can I achieve it?
In order to make the scrollbar narrower, you need to edit User/theme_override/scroll_puck.png and scroll_puck_horiz.png so that it is narrower. Then, set "content_margin" to something like this:
"content_margin": [8, 12],
and play around with the first number until you get a width you like.

How to show all x-axis tick values in Plotly?

I am using this library
https://plot.ly/nodejs/axes/
to plot graphs in node.js. I have this code:
var data = [
{
x: xs,
y: ys,
type: "scatter"
}
];
var graphOptions = {filename: "date-axes", fileopt: "overwrite"};
plotly.plot(data, graphOptions, function (err, msg) {
console.log(msg);
console.log("DONE!");
});
to plot a graph with 5000 x-axis points. The problem is that in the rendered image, it x-axis values are not continuously increment by for each value I put. There is a rather large step, for example, if the x-axis labels are
['item1', 'item2', ..., 'item5000']
then it outputs with labels
['item1', 'item10', ..., 'item5000']
All the yaxis points are there, but I just want to see all x-axis labels.
Does anyone know what setting enables this? I assume that they did this by default so the text labels don't overlap each other, but in my case I want to see them all.
Thanks
I am using Python, though I have encountered the same problem. When you are specifying the layout of your chart, you need to set tickmode='linear', at least it worked for me!
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
layout = go.Layout(
title='some title',
xaxis=dict(
title='Xaxis Name',
tickmode='linear')
Use layout.xaxis.dtick
Example here: https://plot.ly/nodejs/axes/
I run into the same problem and I managed to solve it: the trick is to define your values on xaxis as "categorical".
This is what my code looked like:
var layout = {
xaxis: {
tickangle: 35,
showticklabels: true,
type: 'category',
}
};
Plotly.newPlot(divname, data, layout);

How to set custom colors on jqplot mekko chart?

Is there any way to set specific background colors for the mekko chart in jqplot?
Examples on the jqplot website always show the same set of colors.
I haven't used that particular chart in jqPlot, but this usually works for assigning colours:
series: [
{ color: "#aaff11" }, // series 1 color
{ color: "#991166" }, // series 2 color
{ color: "#33ff66" } // series 3 color (and so on)
]
where series above is a key in the options object passed to $.jqplot(id, data, options).
See the docs for more info.

How can i fill color for dataseries below or above the threshold using Flot?

How to fill color below or above the threshold. currently threshold plugin changes the line of the color but i need to fill the color on the dataseries (eg: below : 5 or above :5 ) when the line is drawing on the canvas using flot line chart. can anyone suggest me. thanks
Are you saying your fill color doesn't change above/below a certain threshold, or that you only want to show fill if it is above/below a certain threshold? If its the former, this works for me just by setting fill to true in the series options:
$.plot("#placeholder", [{
data: d1,
threshold: {
below: 5,
color: "rgb(200, 20, 30)"
}}], {
series: {
lines: {
show: true,
fill: true
}
}
});
See this fiddle for working example.

How to i set jqplot bar chart colours per bar?

I'm trying to set the colours of my jqplot bar chart bars. There will always be six bars present, grouped into sets of 2 bars. Here is an example of the data being plotted:
line1 = [6000, 5000, 5500];
line2 = [16000, 10000, 14000];
I've used the following so far:
seriesColors: ["#F3CBBF", "#BFDDE5", "#CF3501", "#027997", "#CF3501", "#027997"],
But jqplot alternates between the first 2 bars each time instead of using all of the declared colours. This is probably as it only determines 2 series being present, one per set of data.
Is there a way to set the bar colours explicitly?
I do this using the varyBarColor method so you can list the different colours for the bars in a simple array like you have done already but if there is only one series it will use these colors for each bar instead. Here is an example of my code:
plot1 = $.jqplot('chart1', [s1], {
title: 'Example Income Graph',
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
rendererOptions:{ varyBarColor : true },
pointLabels: { show : true }
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
label:'Net Growth (%)',
ticks: ticks
},
yaxis:{
label:'Income (£)',
tickOptions:{ formatString:'%d'},
autoscale:true,
min:0,
max:10000
}
},
seriesColors: [ "#eee", "#ccc", "#999"],
highlighter: { show: false }
});
In this graph I had one series with 3 bars and they are each a different colour grey.
This is pretty old, but still doesn't have the right answer, and it took me a while to figure it out, so here it goes.
You need two things:
Set the varyBarColor and a series array that contains the series colors for each series, passed at the same level as seriesDefaults, such as:
plot1 = $.jqplot('chart1', [s1, s2], {
title: 'Example',
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
rendererOptions:{ varyBarColor : true },
pointLabels: { show : true }
},
series: [{seriesColors: ["#F3CBBF", "#BFDDE5", "#CF3501"]},
{seriesColors: ["#027997", "#CF3501", "#027997"]}]
}
try like this
series:[{renderer:$.jqplot.BarRenderer , seriesColors: ["#F3CBBF", "#BFDDE5", #CF3501","#eee", "#ccc", "#999"] }]

Resources