I would like to create a histogram to plot real values such as
values = [17.711934920693217, 21.962771788060337, 24.570616100324703, 18.862357360933803, 19.35670692079581, 16.21371067895039, 15.723282991698177, 13.420629746222984, 10.346425858632237].
I'm using pyplot.hist but all I obtain is an empty histogram. Is it possibile to plot these values directly?
I'm not exactly sure what you mean in your question by "real values", do you mean setting the heights of the bars? an expected result would be good.
However, you could possibly want to use plt.bar instead
plt.bar(range(len(values)), values)
Related
Okay, I love to use excel to model my complex heat convection problem in a very visual way.
But now I want to compare the result for different input values. Is there a way to create a plot where x is my input variable (in a range i can decide) and y the result (which can be found in a different cell)?
I know, normally you would need to create a table that has all x values in one column and all y values are calculated in ONE STEP in an adjacent cell. But as my calculation is quite complex, this is not the case.
So in a very simplified way, this is how my excel looks like:
Simplified version of my problem
How would you create a scatter plot of such a relation?
I tried to google the problem, but I didn't find a similar question
I am trying to count and plot the number of data points I have for each area by day, so far I have:
But I would like to show the number of instances of each county per day, with the end goal of plotting them on a line graph, like:
Only I would want to plot each county on its own line, rather than the total which I have plotted above.
Update:
I have managed to get this from the answers provided:
Which is great and exactly what I was looking for. However, in hindsight, this looks a little messy and not very descriptive even for the short period plotted let alone if I were to plot this for a couple of years worth of data.
So I'm thinking to plot this indivually on an 8 grid plot. But when I try to plot this for one county I am getting the boolean values. As below:
What would be the best way to plot only the True values?
You can try
df.county.groupby([df.date_stamp, df.county]).count().unstack().plot();
df.county...count() is the numerical series you want to plot.
groupby([df.date_stamp, df.county]) groups first by date_stamp, then by country (the order matters).
unstack will create a Dataframe whose index is the time stamp, and columns are counties.
plot(); will plot it (and the ; suppresses the unnecessary output).
Edit
To plot it on separate plots, you could do something like
for county in df.county.unique():
this_county = df[df.county == county]
this_county.county.groupby(df.date_stamp).count().plot();
title(county);
show();
pd.crosstab(df['date_stamp'],df['county']).plot()
EDIT: question changed, if you want them in subplots instead of lines:
pd.crosstab(df['date_stamp'],df['county']).plot(subplots=True)
The key in drawing each county as a separate line is that each county needs to be in a different column. If you just want to count them, crosstab is then probably the shortest way to achieve that result. For example:
Then the result is:
When subplots=True:
Good evening,
I have a problem with Gnuplot. I tried to sum up my problem to make the comprehension easier.
What I have : 2 sets of data, the first one is my experimental data, about 20 points, the second one is my numerical data, about 300 points. But the two sets don't have the same abscissa.
What I want to have : I want my numerical data be interpolate on the x-experimental abscissa.
I know it is possible to do that with Xmgrace (paragraph Interpolation at http://plasma-gate.weizmann.ac.il/Xmgr/doc/trans.html#interp) but with Gnuplot ?
What I want to have in addition : is it possible, then, to subtract the y-experimental data of my y-numerical data at the x-experimental abscissa points ?
Thank you in advance for your answer,
zackalucard
You cannot interpolate the ordinate values of one set to the abscissa values of the other. gnuplot has no mechanism for that.
You can however plot both datasets using one of the smoothing algorithms (check "help smooth") with common abscissa values (which might (be made to) coincide with the original values of one set.)
set table "data1.tmp"
plot dataf1 smooth cspline
set xrange [GPVAL_x_min:GPVAL_X_max] # fix xrange settings
set table "data2.tmp"
plot dataf2 smooth cspline
unset table
Now you have the interpolated data in two temporary files, and only need to combine them into one:
system("paste data1.tmp data2.tmp > correlation.dat") # unixoid "paste" command
plot "correlation.dat" using 2:4
(If you have a sensible fit function for both datasets, the whole thing becomes much easier : plot dataf1 using (fit1($1)):(fit2($1)))
You can use smoothing, this should do the trick
plot "DATA" smooth csplines
(csplines is just one options, there others, e.g. bezier)
But I don't think you can automatically determine the intersection of the smoothed curved. You use the mouse to determine the intersection visually, or alternatively fit some functions f(x) and g(x) to your curves and solve f(x)=g(x) analytically
I have a series of numbers in a file that I can already plot using gnuplot.
The tricky question: I have a bunch of ranges (positions), like
1-11
12-50
51-500
500-512
From this I can calculate the length of the actual range. Based on this lenght, I want to dynamically scale the x-axis for that actual range. Bigger length should produce more "compression" on the x-axis.
I am not sure I understand your question. Does
set xrange [51:500]
do what you want?
I am using gnuplot (Version 4.4 patchlevel 2) to generate rowstacked histograms, very similar to the example called "Stacked histograms by percent" from the gnuplot demo site at http://www.gnuplot.info/demo/histograms.html
I want to display the values of each stacked box within it.
I.e. I want to display the actual numerical value (in percent and/or the absolute number) of each box.
How can I do that?
How many numbers do you want to enter.
If it is just a few then have you tried
set label "label" at 2,3
If there are many then you can write a script to decide where to put the numbers - something like here
Plotting arrows with gnuplot
Don't know a way to do it by magic, although I am not very familiar with rowstacked histograms
Tom