pandas group bar chart - pandas

I am trying to plot group bar chart
df1=sample_data.sort_values("Population")
df2=df1[(df1.Population < 500000)]
df3=df2[["city_id","CAC","Avg check"]]
df3.plot.bar(rot=0)
When the last command plots entire dataframe, I really wanted to use city_id as X label, and could not figure out how to make it done. Would anyone advise me on a right way?
Thanks,
Evgeny.

Related

Stacked bar chart from one column pandas or dictionary

I have been trying to create a stacked bar chart from simple data.
Assume the dictionary:
data ={A:2,B:3, C:4, D:5}
I would like to create a bar chart that shows like this:
I cant do it manually (i.e. dividing A by the total and so on) since I have a dictionary that consists of 20 keys.
I feel like it should be so simple but I can't figure it out
Thanks
You can try:
pd.Series(data).to_frame().T.plot.bar(stacked=True)
Output:

Conditional label for selected stack bar chart in facet ggplots 2

I am looking for a help to display labels for a selected stack bar, e.g. "Net impacts" stack, in the facet_wrap stack figure below. I tried to use geom_text(aes(label=ifelse())) but it does not work.
Any suggestion would be grateful. Thanks in advance.
Stack-bars chart Figure
Update: So, instead of displaying the labels for a selected stack-bar, I've just come up with the combination of stack-bar and point chart figure Stack-bars and Points chart. I am satisfied with the yellow points presenting sum of stack-bars at each column, though it would be much better if these values can be showed on each bar. Any suggestion please?!
In addition, is it possible to show scientific number as labels for the points/stack-bars?

Is there any built in function in pandas to subtract various columns to manipulate a stacked bar chart?

I hope I do not brake too much rules (this is my first post).
First Things first: I'm sorry, but I cannot post an image of my plots or Code right now. So I created a pretty image in paint. On the left side you see what I want to create, on the right side you see what I create right now.
Example
I was able to make a barchart as shown on the left side with lots of detours. Since I have to analyse lots of data in similar charts I want to use the built in plot function of Pandas.
What I need: stacked bar chart, where the values are not summed up (like shown in the right image) but the difference of the values are summed up (like shown in the left image). So if s1 = 2 and s2 = 6 and i just do some stuff like groupby().unstack().plot(kind='bar', stacked=True) I got stacked bars which end at y=2 for s1 and y=8 for s2 (like shown in the right diagram).
How can I modify my code so that I will get y=2 for s1 and y=6 for s2?.
I thought about diff(), but the result was definetly not like expected.
I hope my question is clear.
Thanks for your adviced and best regards
Arnfried

Overlapping bar chart with multiple axis in PowerBi

I would like to have a overlapping bar chart in PowerBi with multiple axis. I have an example from Excel which I would prefer to recreate in PowerBi if this is possible.
Here the example:
Is this possible in PowerBi? Maybe by using a custom visual I don't know off.
Thanks in advance,
Multiple axes? Yes! Overlapping bars? No!
Using a Line and Clustered Column Chart is the way to go:
Here's a demo using some random numbers:
Date A B C
07.08.2018 0,359008828 0,993689927 0,8
08.08.2018 0,127630228 0,449164386 0,8
09.08.2018 0,431825126 0,615830289 0,8
10.08.2018 0,269830973 0,984995499 0,8
11.08.2018 0,27416548 0,64248379 0,8
12.08.2018 0,777712123 0,740108131 0,8
13.08.2018 0,264229043 0,242084953 0,8
14.08.2018 0,49124239 0,144428206 0,8
15.08.2018 0,242050334 0,020032871 0,8
16.08.2018 0,316102617 0,644935538 0,8
Use Enter Data to get a table with these numbers under Fields:
Click Line and Clustered Column Chart under Visualizations
Drag Date to Shared Axis, and change the date hierarchy to simple date using the drop down menu next to Date.
Drag C to Line Values, and A and B to Column values:
Under Y axis, set Show Secondary to On
And that's as close as you're going to get to replicate your Excel Chart at the time being as far as I know.
It's certainly not an ideal solution, but it is possible to place charts on top of each other. This is the result of two bar charts superimposed upon each other:
Note: In order to have control over the column width, you need to change the x-axis to categorical and adjust the inner padding.
There are multiple custom visuals available on the appsource now. Search for lipstick charts. see screenshot below. one of those is here
https://appsource.microsoft.com/en-US/product/power-bi-visuals/yavdaanalyticspvtltd1628223732998.lipstickcolumnpro?tab=Overview

Office.Interop.Excel How to get axis from series

I am using Microsoft.Office.Interop.Excel to create a chart. Some of my series in chart series collection are logarithmic, so I want to get hold of axis related a particular series, to set scale type to logarithmic.
Here is a way you could do it:
xlAxisValue = CType(xlChart.Axes(, Excel.XlAxisGroup.xlPrimary), Excel.Axes)
xlAxisValue.Item(Excel.XlAxisType.xlValue).ScaleType = Excel.XlScaleType.xlScaleLogarithmic
It is a generic example, if it is not working plese post your code.