Multiple charts in one figure in Bokeh - python

Is it possible in Bokeh to combine multiple high-level charts in one plot? For example Line chart with Scatter chart? Thanks.

Yes (as of 0.8.1), use hplot, vplot or gridplot from bokeh.charts See, for example:
https://github.com/bokeh/bokeh/blob/master/examples/charts/scatter.py#L43

Related

Plotting a grouped stacked bar chart

I am trying to create a grouped, stacked bar chart. I was able to do it in excel and this image shows what I am trying to create but I want to do it through Python. I have all the data in a pandas data frame that is able to create separate stacked bar charts but I cannot get the grouping as seen in excel.
Excel Formatting:
If you could do it in Excel with easy then I strongly suggest you to do it with Excel. Unless you have other requirements.
There are many libraries you can use to create this type of plot: matplotlib, seaborn, or plotly. The one I use most is plotly. You can see the list of sample figures of plotly here: https://plotly.com/python/
Or you can join plotly community, there are many pros there might help with figure. I find there is few pros on figures in stackoverflow to plotly community: https://community.plotly.com/

How to plot independent graphs next to each other using seaborn?

my problem is that I could only find answers for plots sharing the same y-axis units.
My graphs are defined as follows:
#Plot1
sns.set_style("white")
sns.catplot(y="Reaction_cd_positive", x="Flux_cd_positive",
kind="bar",height=4, data=CDP,aspect=1.5)
#Plot2
sns.catplot(y="Reaction_cd_negative",x="Flux_cd_negative",
kind="bar",height=4, data=CDN, aspect=1.5)
Thank you in advance!
Ok, let me translate this. You are using seaborn in a jupyter notebook. You want 2 barplots next to each other within the same figure, instead of two individual figures. Since catplot produces a figure by itself, there are two options.
Create a single catplot with two subplots. To this end you would need to concatenate your two DataFrames into a single one, then use the col argument to split the data into the two subplots.
Create a subplot grid with matplotlib first, then plot a barplot into each of the subplots. This is shown in this question.

Why no colors in bokeh plot's legend

In Bokeh 0.12.2, I was able to make a stacked bar chart with various hover tooltips using plotting and VBars. I also enabled a legend for the plot. However, my vbars are colored and the colors for each vbar (each stack) are not appearing in the legend. Only the names for the stack in the legend are appearing. Is this not an implemented feature yet or a bug maybe? Or maybe I'm missing something?
what my chart looks like
This was due to a bug in the bokeh source code which is being fixed if not fixed already.

Bokeh Overlapping Bar Chart?

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.

matplotlib pie charts leave labels from previous pie chart

I have a small Django app that produces two different pie charts.
But the labels from the first chart that's displayed reappear in
the second chart.
I'm just using:
plt.pie(...)
plt.savefig(...)
In the same view for two different pie charts using two different
(small) datasets.
Is there some 'clear' or 'reset' method I need to call after the saving of the
plot?
You can leave your code unchanged, and clean your figure by calling clf() after having saved the first plot and before generating the second plot.
By doing so, you are interfacing with matplotlib state-machine. Matplotlib automatically creates figure and axes for you, and you use keep using the same figure.
The alternative is to use matplotlib in a more object-oriented way. You ask matplotlib to create figure and axes object, and then you do all the rest by calling methods of those objects:
fig1,ax1=plt.subplots()
fig2,ax2=plt.subplots()
ax1.pie(...)
ax2.pie(...)
fig1.savefig(...)
fig2.savefig(...)
The usage FAQ here clarifies the two options.

Categories