I have the following graphs done using this code:
legend(rows(3) size(small) bmargin(zero) rowgap(0) colgap(0) label (2 "Charcoal") label(3 "Rudimentary wood planks") label(4 "Animal dung") label(1 "Others")) ///
blabel(bar, format(%9.0f) color(white) size(vsmall) position(inside)) bargap(5) graphregion(color(white)) ytitle("Percentage %") ///
ylabel(, nogrid) b1title("") l1title("") title("Cooking fuel")
graph save "11", replace
catplot floor1 [aw=${weight}], recast(bar) percent asyvars stack ///
legend(rows(2) label(2 "Sand/Earth") label(3 "Dung") label(1 "Others") size(small) bmargin(zero) rowgap(0) colgap(0)) ///
blabel(bar, format(%9.0f) color(white) size(vsmall) position(inside)) bargap(5) graphregion(color(white)) ytitle("Percentage %") ///
ylabel(, nogrid) b1title("") l1title("") title("Floor")
graph save "22", replace
catplot watersource [aw=${weight}], recast(bar) percent asyvars stack ///
legend(rows(2) size(small) bmargin(zero) rowgap(0) colgap(0) label(1 "Other") label(2 "Public tap") label(3 "Tubewell/Borehole") label(4 "River/stream/lake")) ///
blabel(bar, format(%9.0f) color(white) size(vsmall) position(inside)) bargap(5) graphregion(color(white)) ytitle("Percentage %") ///
ylabel(, nogrid) b1title("") l1title("") title("Water source")
graph save "33", replace
catplot toilet [aw=${weight}], recast(bar) percent asyvars stack ///
legend(rows(3) size(small)) legend(label(1 "Other") label(2 "Pit latrine with slab") label(3 "Pit latrine without slab/open") label(4 "No facilities/in the bush")) ///
blabel(bar, format(%9.0f) color(white) size(vsmall) position(inside)) bargap(5) ytitle("Percentage %") ///
ylabel(, nogrid) b1title("") l1title("") title("Sanitation")
graph save "44", replace
graph combine "11" "22" "33" "44", iscale(0.8)
This is the output. The legend is overlapping the graph area and doesn't look great. Any idea on how to stop that without making the legend size/font even smaller?
Thanks!!
Related
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'
)
I’m new to plotly and I’m creating a gantt chart using px.timeline. There are 3 categories of data in my dataset, a normal task with a start and end time, and two types of task where the start and end time are same. I want the normal task to be a rectangle (which is how it is being plot) and the other two tasks to have a hourglass marker and a triangle marker instead of a very thin line ?
This is how my data looks :
data = [dict(Task=’’, start=’’, end=’’, shape=’<rect, hour, tri>’)]
Sample Data :
df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-01-01', shape='hourglass'),
dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15', shape='rectangle'),
dict(Task="Job C", Start='2009-05-30', Finish='2009-05-30', shape='triangle')]
Code :
fig = px.timeline(data, x_start="Start", x_end="Finish", y="Task")
fig.update_yaxes(autorange="reversed", ticklabelposition="outside left")
fig.update_layout(showlegend=False, height=2000, width=1255, margin_pad=10)
fig.show()
Example:
Sample Plot in Excel
Is there any way I can achieve this ?
Thanks !
I solved this after some hours of searching.
Split the data into three each corresponding to 3 different shapes and then plot and combine.
Create 3 individual Plots :
rect = px.timeline(rect, x_start="Start", x_end="Finish", y="Task", color="color")
dia = px.scatter(dia, x="Start", y="Task", color="color", symbol_sequence=['diamond'])
coll = px.scatter(coll, x="Start", y="Task", color="color", symbol_sequence=['hourglass'])
Update traces for individual plots if needed :
rect.update_traces(marker=dict(line=dict(width=1, color='black')))
dia.update_traces(marker=dict(size=12, line=dict(width=2)))
coll.update_traces(marker=dict(size=12, line=dict(width=2)))
Set the timeline plot's axis:
rect.update_xaxes(tickformat="%H:%M:%S.%L", tickmode='linear', dtick='120000')
rect.update_yaxes(autorange='reversed')
rect.update_layout(title=title, showlegend=False, height=2800, width=2000)
Overlay all Plots:
new_fig = go.Figure(data=rect.data + dia.data + coll.data, layout=rect.layout)
new_fig.show()
I've got a SciChartSurface where I support zooming as follows:
Zoom x-axis on regular scrolling.
Zoom y-axis on scrolling + CTRL
Pan x-axis on scrolling + Shift
I'd like to also enable panning in the X-direction when the user either scrolls horizontally on a trackpad or uses a horizontal scroll wheel (thumb-wheel). However, I'm not sure how to go about doing this.
Here's the extended MouseWheelZoomModifier I've been using. Can I somehow send it information about my scrolling behavior? Can I somehow just treat the sideways/horizontal scrolling as Shift + scroll? Thanks!
/// <summary>
/// Extended <see cref="MouseWheelZoomModifier"/> which modifies zoom
/// behavior based on modifier keys so that scrolling while holding CTRL
/// zooms vertically and doing so while holding SHIFT pans horizontally.
/// </summary>
class MouseWheelZoomModifierEx : MouseWheelZoomModifier {
public override void OnModifierMouseWheel(ModifierMouseArgs e) {
switch (e.Modifier) {
case MouseModifier.Ctrl:
ActionType = ActionType.Zoom;
XyDirection = XyDirection.YDirection;
break;
case MouseModifier.Shift:
ActionType = ActionType.Pan;
XyDirection = XyDirection.XDirection;
break;
default:
ActionType = ActionType.Zoom;
XyDirection = XyDirection.XDirection;
break;
}
// e.Modifier is set to None so that the base implementation of
// OnModifierMouseWheel doesn't change ActionType and XyDirection again.
e.Modifier = MouseModifier.None;
base.OnModifierMouseWheel(e);
}
}
In SciChart you can add any custom zoom and pan behaviors using the ChartModifierBase API.
As well as the standard methods which you can override (like OnModifierMouseWheel, OnModifierMouseDown, OnModifierMouseUp) you can also subscribe to events directly on the ParentSurface.
Have a look at this KB article: Custom ChartModifiers - Part 2 - Custom ZoomPanModifier and Zooming on KeyPress.
Up to date accompanying source code is here.
So my suggestion is take the SimpleZoomInOutModifier and modify it to respond to mouse wheel events instead of key events.
Does that help?
I have a highcharts "area" graph, and for every point on that graph i want to add a dashed border on the colored area all the way to the bottom.
To add dashed borders to your area graph, mention the dashstyle in which each series will be represented in.
Sample Snippet
Series:[{
name: 'USA',
data: [null, null, 10421, 10358, 10295, 10104 ],
dashStyle: 'longdash'
}]
Possible Values
Solid
ShortDash
ShortDot
ShortDashDot
ShortDashDotDot
Dot
Dash
LongDash
DashDot
LongDashDot
LongDashDotDot
Demo
Jsfiddle is here.
I am running the following command to draw a few X,Y points in gnuplot:
plot "Output.tsv" using ($2+3):($3+3):1 with labels, "Output.tsv" using 2:3
Some of the data points are very close to each other and it makes the label unreadable. Is there a way to ask gnuplot to eliminate/reduce the overlap between labels?
I think you could consider 3 options:
1) make your graph huge and hope your labels do not overlap
2) plot the points as different series with each item having its own legend
3) use letters instead of labels, you can put a letter at each point using
plot "???" using 1:2
plot "" using 1:2:(stringcolumn(3) ne 'compare to' ? 'if equal' : 'if not equal' ) with labels
the stringcolumn function looks in column 3, compares the value to the string 'compareto' and if there is a match it puts 'if equal' at that location, otherwise 'if not equal'
Hence, I see something like Simulator in your graph, you could keep the green point and put an S with it/on it using
plot "" using 1:2:(stringcolumn(3) ne 'Simulator' ? 'S' : '' ) with labels
I hope this helps.