How to plot histogram where a country is a bin - pandas

I am attempting to plot a histogram where the y-axis should be the count and the x-axis (i.e. the bins) should be composed of all the countries, but I cannot seem to figure out the code.
I have tried following https://datasciencelab.wordpress.com/tag/pandas/ and How to create Histograms in Panda Python Using Specific Rows and Columns in Data Frame, but both of those are for bar graphs and not for histograms.
per_country = df.groupby(['COUNTRY'])[['TOTAL']].sum()
per_country = per_country.sort_values('TOTAL')
per_country.head()
medals_per_country['TOTAL'].plot(kind='hist') # if hist is changed to bar, then it works, but I need a histogram and not a bar graph
The result should be a histogram where the x-axis includes a label for each country and the y-axis is the total for each country. Right now the bins are just based on the 'TOTAL', whereas the y-axis is the number of countries with said 'TOTAL'.
Can someone please point me in the right direction? Thank you!

Related

Binary treatment based on a continuous variable (Stata)

I want to create a scatter plot showing my treatment assignment on the y-axis and the margin of winning on the x-axis.
To create a binary treatment variable, where a margin over 0 indicates that a Republican candidate won the local election.
gen republican_win = (margin>0)
Here is a data example:
* Example generated by -dataex-. For more info, type help dataex
clear
input double margin float republican_win
-.356066316366196 0
-.54347825050354 0
-.204092293977737 0
-.449720650911331 1
-.201149433851242 1
-.505899667739868 0
-.206885248422623 1
end
To generate a scatter plot, I ran this. While the code ran well, I was wondering if it would be possible to display a continuous distribution of the margin of Republican wins and losses?
scatter margin republican_win
You can use the predicted probabilities by storing them in a variable, and then plot it at the same time as your scatter plot.
I would then reverse the axes to show your logistic distribution.
logit republican_win margin
predict win_hat
twoway scatter win_hat republican_win margin, ///
connect(l i) msymbol(i 0) sort ylabel(0 1)
There are not enough data points in your data example to show a nice fitted curve, but I'm sure it will look better on your whole dataset.

Grouped errorbar with array of strings as data points

I have different measurements from two+ sensors. I want to compare the performance of each sensor for each measurement with errorbars (mean and std). I have no problems creating and formatting a standard errorbar plot for one y (sensor) and yerr per data point (measurement). But i'm trying to create a plot like this:
I can neither find the option to do this in the matplotlib documentation nor when i google it or search this site. The closest i found was this thread:
matplotlib: grouping error bars for each x-axes tick
But this solution doesn't work for me since my datapoints aren't numbers but a pandas dataframe index of strings.
So i found the solution in the Matplotlib documentation after all. Here's the link for people who might have the same question:
A bar plot with errorbars and height labels on individual bars.

subplot with shared axis but different ticks and labels

I make a plot with different subplots (using gridspec.GridSpec). Two subplots share the same x-axis (sharex=ax1 in the definition of the second subplot).
However, as one subplot shows the indices of the chronologically sorted data, and the second subplot shows the corresponding decades, I want seperate ticks and labels for the x-axes of both plots. This seems not possible, a unique set of labels and ticks are assigned to both subplots. Until now, I can only:
use different x-axes and thus assign two sets of ticks and labels.
In that case, the axes are not alligned although
ax1.set_xlim([start, stop]) are similarly defined for both subplots
use a common x-axis and one set of ticks and labels
I do not find a solution for this on the internet. Is someone able to help? Thank you in advance!

3d scatter plot with mplot3d with missing frequency as z axis

I am trying to plot some data but I only have my x and y axis given. I would like to get the frequency for my z axis like I would in a histogram. But I don't really want a histogram, rather a scatter plot or a surface plot.
This is my histogram right now, quite messy.
Is it possible to use the function of the histogram to get the frequency of the points but have a scatter/surface plot instead? Or to change the bars of the histogram to something like dots or something similar?
None of my data points have the same value, so I would like them to be sorted in intervals, like [0,0.05] or so, that's why I am trying to find another solution than calculating this.

2 category axis in Column chart in Webi Reports

Is it possible to have 2 category axis(x -axis) values one with bar and other with line and one measure for both? If possible please let me know how to achieve it.
Thanks
Niki
Multiple Y-axis are possible, but you can only have one X-axis per chart. That said, you can have an X-axis with multiple dimensions on it (e.g. City and State).
Each measure will be plotted (aggregated) according to the dimensions added to the X-axis.
You cannot have different visualisations for the same measure on the same chart (e.g. a column and a line for the same measure), unless you have a chart with 2 Y-axis. Whether this would be a good visualisation of your data is a different matter.