Python graph with three entities and legends - python

I have three lists in python. the lists are given below
Server_name=['server_1','server_1','server_1', 'server_1','server_2', 'server_2','server_2','server_2']
Month_name=['may','may','june','aug','may','june','july','sept']
Error_count=[10,20,10,30,40,10,20,50]
I want to plot a graph something like below
The above diagram shows that the for all the servers and corresponding month the total count of errors are taken and the graph is plot.
I have tried different scenarios but was unable to get the perfect graph with legends and total count for all three entities.
How should I built my code so I can get the above graph, please suggest
Appreciate your help.

Try using vincent module. It is used to produce these type of graphs
https://github.com/wrobstory/vincent

Related

Frequency vs total count bar plot in python

I have a datafram with following structure
,mphA,gyrA,parC,tet59,qnrVC
sample1,TRUE,FALSE,FALSE,FALSE,FALSE
sample2,TRUE,FALSE,FALSE,FALSE,TRUE
sample3,FALSE,FALSE,FALSE,TRUE,FALSE
sample4,FALSE,FALSE,FALSE,TRUE,TRUE
sample5,TRUE,FALSE,TRUE,FALSE,TRUE
sample6,TRUE,TRUE,FALSE,FALSE,FALSE
sample7,TRUE,TRUE,TRUE,FALSE,TRUE
sample8,TRUE,TRUE,TRUE,TRUE,TRUE
sample9,FALSE,TRUE,TRUE,FALSE,TRUE
sample10,TRUE,TRUE,FALSE,FALSE,TRUE
And I need to generate a frequency vs total count bar plot similar to the following figure in python. Its a combination of 3 plots so I guess you need to plot them independently and put them in a single canvas. I frequently see this plot in journals so I guess it should be implemented already. However, I did not have any success with online search. Does anybody know how it can be done? Thanks.
It can be done easily using UpSetPlot
https://pypi.org/project/UpSetPlot/

Is there a way to count the number of points within a certain area on a graph?

I've got output graphs that look like this:
My question is, is there an easy way for me to count the number of points within each of the obvious 'lines' or 'streaks' of particles? In other words, I need to find the density of each of the streaks separately. Most of them are overlapping which is where my issue comes in.
I've tried specifying x and y limits but again, the overlapping comes into play. The existing code is just importing and plotting values.
Ken, thanks for your comment. I went along that path, I found that single linkage works best for the type of clusters I have. I also had to find a multiplying factor for my own data first, because the clustering was failing with the data overlapping. With this data the different colours represent different clusters. The dendrogram x-axis is labelled with the cluster densities, but they aren't in order! I'm yet to find an efficient way around this. I manually adjusted the dendrogram to produce 2 clusters first, which told me the density of the first shell (it produced 2 clusters, 1 of the first shell and 1 with everything else). Then repeated it for 3,4, etc.
Sorry if none of this makes sense! It's quite late/early here.

Pandas groupby group visualization by dividing between groups

I am facing a very annoying problem. I have a dataset where I have the sales amounts for different regions and years.
I would like to visualize the yearly aggregated sales amounts based on different regions.
Below is my groupby code:
groups = df.groupby(["Region", "Year"])["Sales"].sum()
groups.plot.bar(color="blue")
plt.show()
And the output I get looks like this:
I have two questions:
1. How could I somehow separate the region and year bars from each other as this way my chart looks really confusing? A separator line or actually a highlighter would also work, or even a bigger gap would be a good solution to me.
(Please see below, what I mean:)
or
I have no clue at all, how to solve this problem.
Question no 2. How could I have this image sorted by the regions with most sales, followed by the second most sales yearly, and so on? Kind of sorting in a descending order based on regions.
I tried the code below:
groups = df.groupby(["Region", "Year"])["Sales"].sum()
groups2=groups.sort_values(axis=[0][1],ascending=False)
groups.plot.bar(color="blue")
plt.show()
But I get a list index out of range error. Using axis=[0] does not solve the problem.
Thank you very much for your help in advance!
Following ChrisD's advice you can obtain a working result with seaborn's catplot to display your bars into different facets by region.
sns.catplot(x='Year', y='Sales', col='Region', data=groups, kind='bar')
You may have to format the aspect ratios for your display purposes.

Creating heatmap of US locations changing over time with python

The data I have is a set of occurrences of a general event in various US states for a given set of years. All I care about illustrating is 1) the year of the occurrence(s), and 2) the location (state) of the occurrence(s).
I am using state capital latitude and longitudes as the location of each point plotted, and want each point on the map to have a color corresponding to the number of occurrences in that state, in that year. I would like to create a map subplot; essentially create one of these maps for each year of available data and plot all those maps together to visualize the change in location of events over time.
So far, the closest thing I have found I can do is create a scattergeo plot using python and plotly (i.e. the figure at the bottom of this: https://plot.ly/python/map-subplots-and-small-multiples/ ), which gives me the desired map subplot over time, but I cannot figure out how to make each of the submaps into a heat map, rather than a simple scatterplot. Any ideas would be greatly appreciated! As you can probably tell I'm a python noob, but I hope I was able to make my problem clear!

Plotting graphs with error ribbons in python

for a while I've been trying to come up with a good way to graphically represent a data series along with its estimated error.
Recently I saw some graphs where the data was plotted as a line, with a background 'ribbon' filling the area between the lines plotting data +/- sigma.
Is there a name for this type of graph, and is there any python toolkit which has the capability to make such plots?
A simple way to fake it with matplotlib would also be useful - right now I'm just plotting three lines, but I don't know how to fill the area between them.
I would use the fill_between method. Look at the Our Favorite Recipes section of the manual for matplotlib for some good examples. They have one that looks like this:
and another that looks like this:

Categories