My output graph is flourished with the data points on the x axis and it is not in a readable form - jupyter-notebook

The output graph is flourished with the data points on the x axis and it is not in a readable form. Also, matplotlib give multiple graphs if I load and concatenate .csv files for a group of years.I seem not to find the right code for making a good presentation for the graph.
This is the code for the Function to plot a bar chart of the given locations(Variables)
[enter image description here](https://i.stack.imgur.com/sZcHX.jpg)def plot_var(var='new_cases',
location='Kenya'):
"""
Plots a bar chart of the given variable over the date range
"""
assert type(var)==str, "Expected string as the variable name"
assert type(location)==str, "Expected string as the state name"
y = df[df['location']==location][var]
x = df[df['location']==location]['date']
plt.figure(figsize=(10,6))
plt.title("Plot of \"{}\" for {}".format(var,location),fontsize=18)
plt.bar(x=x,height=y,edgecolor='k',color='orange')
plt.grid(True)
plt.xticks(fontsize=8,rotation=45)
plt.yticks(fontsize=8)
plt.show()

Related

Plotting a legend using legend(x,y ....) but x axis are dates in R

I'm trying to put a legend on a line graph using legend(x,y, legend=c("","").... etc. I've changed the date to numeric data and used that for x and it plots, so I know the rest of its right. but when x is a date I'm not sure what to use for x to get the legend to show on the graph.
thanks

How to put data point labels on a plot in Julia

I want to plot my data in a particular way like this:
enter image description here
in particular I want to know how to attach the labels arounud the points
Here it is:
using Plots, Random
vals = rand(10,2)
p = scatter(vals[:,1], vals[:,2],xlim=[0,1.1])
some_labels=randstring.(fill(5,10))
annotate!.(vals[:,1].+0.01, vals[:,2], text.(some_labels, :red, :left,11))
p

Excel scatter plot x axis displays only sequential numbers but not real data selected for x axis

I have an excel scatter plot with 5 different data series on single chart. First 4 series are working well. When I want to add a new series with similar x-axis data (0.0, 0.4, 0.9 .. ) the plot is displayed with x-axis values as 1,2,3 but not as the data specified.
Changing the chart types did not help. Not sure how can I get the x-axis as data but not as sequential numbers. Any help is appreciated. Thanks.
Added the screenshot of chart and its xaxis data. The values are in number format only just as data for other series. Everytime I am adding a new series on to this, its starting with one number later.... (1,2,3...) next series x axis at (2,3,4....) but not with real x values as selected.
Solved it my slef... The problem is X-axis range is for 18 cells and all the cells had formula with IF condition... When I removed the IF condition, x-axis worked well as numbers
The IF condition I used was "=IF(A10<>"",B10=A10-A4,""), for some reason excel chart considered this as some text and populated the x axis as 1,2,3 but not as the values specified.

Plot Variable Frequency using ggplot2

I'd like to plot a bar graph showing frequency of a string in ggplot. The input file (t1. txt) looks like:
do 4
re 2
mi 5
and my current r script is:
library("ggplot2")
t1<-read.table("t1.txt",header=FALSE,sep='\t')
ggplot(t1,aes(V1))+geom_bar()
However this isn't what I'd like - it has a correct x axis, but the y axis should show the variable from the second column (V2). Can anyone help? Thanks.
All you need to do is put the actual V2 in the command then. The default first two items to aes are x and y. You've only given x.
ggplot(t1,aes(V1,V2))+geom_bar()

How to plot density of two datasets on same scale in one figure?

How to plot the density of a single column dataset as dots? For example
x <- c(1:40)
On the same plot using the same scale of the x-axis and y-axis, how to add another data set as line format which represent the density of another data that represents the equation of
y = exp(-x)
to the plot?
The equation is corrected to be y = exp(-x).
So, by doing plot(density(x)) or plot(density(y)), I got two separated figures. How to add them in the same axis and using dots for x, smoothed line for y?
You can add a line to a plot with the lines() function. Your code, modified to do what you asked for, is the following:
x <- 1:40
y <- exp(-x)
plot(density(x), type = "p")
lines(density(y))
Note that we specified the plot to give us points with the type parameter and then added the density curve for y with lines. The help pages for ?plot, ?par, ?lines would be some insightful reading. Also, check out the R Graph Gallery to view some more sophisticated graphs that generally have the source code attached to them.

Resources