I'm new to plotly/plotly express and i'm having a really hard time finding any working example other than the documentation examples for the library (which are really basic and standard).
I have, let's say a scatter plot, in plotly express:
fig = px.scatter(any_random_data)
And i want to add to that plot an image in a fixed (x,y) position, but i don't know (and can't find!) if there is any kind of method for that.
I've seen there is an add_trace() method to add traces to the plot (i guess), is there any similar function for adding images? (Like add_image() or something)
Altair offers lovely feature to facet charts using facet method. For example, following dataset visualizes nicely:
print(df[['Year', 'Profile', 'Saison', 'Pos']].to_csv())
,Year,Profile,Saison,Pos
0,2017,6.0,Sommer,VL
1,2017,6.0,Winter,VL
13,2017,6.0,Winter,HL
12,2017,6.0,Sommer,HL
18,2017,6.0,Sommer,HR
6,2017,6.0,Sommer,VR
7,2017,6.0,Winter,VR
19,2017,6.0,Winter,HR
14,2018,5.5,Winter,HL
8,2018,5.5,Winter,VR
15,2018,5.5,Sommer,HL
20,2018,4.3,Winter,HR
21,2018,5.0,Sommer,HR
3,2018,5.5,Sommer,VL
2,2018,6.2,Winter,VL
9,2018,4.5,Sommer,VR
17,2019,4.5,Sommer,HL
11,2019,4.2,Sommer,VR
22,2019,3.5,Winter,HR
10,2019,5.28,Winter,VR
5,2019,4.6,Sommer,VL
4,2019,4.9,Winter,VL
16,2019,4.0,Winter,HL
23,2019,4.5,Sommer,HR
with the following command:
alt.Chart(df).mark_bar().encode(x='Year:O', y='Profile:Q').facet(row='Saison:N', column='Pos:N')
But, as you can seem I have still a lot of place horizontally and would like to use it by rearranging Winter plot right next to the Summer plot:
I understand that I already used column grid to facet over attribute Pos, but visually for me Winter and Sommer plots are two separate plots (just like here), which I'd like to place side by side.
I tried to create two different charts in the same cell and using html emit them side by side, but in Jupyter environment there is a limitation on just one Altair/Vega plot per cell.
Is there any method I can use to arrange these charts horizontally?
In Altair, there is no good way to do this, because faceted charts cannot be nested according to the Vega-Lite schema. However, the Vega-Lite renderer actually does handle this in some cases, despite it technically being disallowed by the schema.
So you can hack it by doing something like this:
chart = alt.Chart(df).mark_bar().encode(
x='Year:O',
y='Profile:Q'
).facet('Saison:N')
spec = alt.FacetChart(
data=df,
spec=chart,
facet=alt.Facet('Pos:N')
).to_json(validate=False)
print(spec)
The resulting spec can be pasted by hand into http://vega.github.io/editor to reveal this (vega editor link):
You'll even notice that the vega editor flags parts of the spec as invalid. This is admittedly not the most satisfying answer, but it sort of works.
Hopefully in the future the Vega-Lite schema will add actual support for nested facets, so they can be used more directly from Altair.
so using the bare minimum code to produce a chart in plotly.py:
from plotly.offline import plot
from plotly.graph_objs import Scatter
plot([Scatter(x=[1, 2, 3, 4, 5], y=[3, 2, 1, 2, 3])])
produces a nice chart with a modebar on top of it. I would like to embed my chart in a website where the bar seems really intrusive. In plotly.js there's a really simple way to disable to modebar as shown here. The solution in plotly.js is merely giving additional parameter: Plotly.newPlot('myDiv', data, layout, {displayModeBar: false});
I know there's a way to save static image from plotly where the modebar is obviously disabled, but that would lose the interactive hover-actions on the plot itself, which are useful, whereas the bar that comes with it is not really that useful in my case. What I'm wondering is if there's a way to do remove the modebar in a similiar fashion to how plotly.js works?
One solution, I suppose would be to always go through the produced HTML-file and add every part of the hover bar to r.modeBarButtonsToRemove, which could turn troublesome in the long run.
I've been able to do it using the config key word argument, like this:
graph = py.plot(
figure,
output_type='div',
auto_open=False,
show_link=False,
config=dict(
displayModeBar=False
)
)
I am a little late here. But just a side note, this won't disable the functions of the top bar so when you hover it will still zoom and pan (which is extremely annoying on plots that are viewed from a mobile device). But making it a static plot isn't a good solution because I still want users on a computer to be able to hover over the points on the plot.
I solved this by changing two of the figure layout settings.
xaxis_fixedrange and yaxis_fixedrange need to be set to True if you want to disable zooming.
Bokeh:
Can anyone provide some guidance on creating the horizontal scroll bar similar to the one shown in the image below such? Does anything of the like exist? Is this feasible without fiddiling D3.js? Graph can be viewed at
https://fred.stlouisfed.org/series/GDP#
Use python-highcharts instead. The graph you showed is apparently using highcharts.
Is it possible to do overlapping bar chart in bokeh like this example in highcharts?
http://www.highcharts.com/demo/column-placement
Yes. You can definitely create this type of chart using Bokeh lower/mid level APIs. That will require some coding to prepare the data and the glyphs. You can create and draw 2 different sources for the background and foreground rects separately. The plotting API docs and the examples on the repo should be helpful.
As a side note, at the moment (0.11 version) the high level Charts API does have a Bar builder function to create Bar charts with just one line but it doesn't support overlapping bars.