Adding datapoints to a boxplot - graphics

R beginner here so sorry for the basic question... I have worked in class to draw some boxplots using the boxplot() function. As part of the assignment I've been asked to add data points to the boxplots. I can't seem to find an argument in the boxplot() function to do this...Is there another function I need to use? Thank you!

I recommend looking into ggplot2 package within R.
You can create multiple visualizations, including a boxplot with the data points shown. This is the ggplot code to do so:
library(ggplot2)
ggplot(df, aes(x=catvar, y=yvar)) +
geom_boxplot()+geom_dotplot(binaxis='y', stackdir='center', dotsize=1)

Related

The x and y axis scaling in Contour plot

When I make a contour plot with Python, I have been using a set_aspect function. Because this allows me to avoid image/contour-lines distortion caused by changing both axis.
: for example, ax1.set_aspect('equal', 'box-forced')
But, I just found that the option 'box-forced' is not valid in Python3.
So my question is, is there any alternative of the 'box-forced' option in Python3? I want exactly the same effect as the ax1.set_aspect('equal', 'box-forced') in Python2.
Thanks!
I just found that there is a function plt.axis('scaled').
It seems that this does what I wanted in a recent version (3.7) of Python3.
You can try this one from the official documentation that I found in as my first recommended page:
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_aspect.html
I'm not sure what you're trying to accomplish here exactly, but you could try the following:
ax1.set_aspect(aspect='equal', adjustable='box')
You could also check the following link which is for the set_adjustable method:
https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.set_anchor.html#matplotlib.axes.Axes.set_anchor
Hope this helps. Good luck!

What the function of checking graph's length(weight) between two nodes in networkx?

I make a Graph by networkx, and it is like that:
now I want to check the distance(weight) between two points, for example point 6 and 7?
Is there some simple syntax can search it like, Graph[6][7]['length']?
You can try this package
https://pypi.org/project/graph-theory/
Check the gd3.distance(n1,n2)

python define style/vairable for line (but not for figure)

I very often plot two types of results - e.g. prediction vs measurement - into a figure for a document, where the look of the corresponding lines/scatters should be match each other in different plots, but at the beginning of the writing/plotting the final look is not decided. I would like to define a bunch of plot options for every such curve, to make it possible to replot them very efficiently.
For example a would like to define the styles like:
s_theory = [linestyle="--", color="grey", marker=None, label="simulation"]
s_measurement = [linestyle=":", color="black", marker="s", markersize="5",label="measurement"]
I would like to apply these magically on plt.plot():
plt.plot(xt,yt,**s_theory)
plt.plot(xm,ym,**s_measurement)
How can I do that? What is the magic word I did not found during my search for this task? I am pretty sure there is a very simple to do that.
Based on the comment of ImportanceOfBeingErnest:
style_sim = {"linestyle":"--", "color":"grey", "marker":"None", "label":"simulation"}
style_meas = {"linestyle":":", "color":"black", "marker":"s", "markersize":5, "label":"measurement"}
plt.plot(xt,yt,**style_sim)
plt.plot(xm,ym,**style_meas)
If you find it useful, please vote up the comment of ImportanceOfBeingErnest!

Using "for" in MatPlotLib

I want to create a histogram serie. However, I also need to use weights (I cannot use seaborn).
I tried to use "for" to create this serie using:
list=range(28,37)
for i in list:
plt.hist(Base.iloc[:,i],weights=Base['weights']
But I got a Strange histogram:
I have 2 questions:
how do I create this serie; and,
what is this strange histogram?
for i in range (28,37)
plt.hist(Base.iloc[:,i],weights=Base['weights']

Wrong fit parameters, Undefined value during function evaluation

I'm trying to do some simple fits using Gnuplot and encountering an error which somehow I'm not able to explain. Seems that I'm doing something terribly wrong with the definition of my function.
I first started with a fit of some functions. The functional form of these is not important as the fits work pretty well, but since they are involved later I'm reporting them as well.
evap(x)=(x>x_fc)?A*qnet(x)/wm2_to_mmh:(x<x_wp)?0:(A*qnet(x)/wm2_to_mmh)*(x-x_wp)/(x_fc-x_wp)
fit evap(x) './fluxes_da_1p0.txt' using 1:2 via A, x_fc, x_wp
sensible(x)=( (qnet(x)/wm2_to_mmh)-evap(x) ) / (1+B)+C
fit sensible(x) './fluxes_da_1p0.txt' using 1:3 via B,C
Then I defined
deltasensible(x)=abs(sensible(x)-sensible(0.454))
deltalatent(x)=abs(evap(x)-evap(0.454))
period_adv=18.0
g(x)=m*deltalatent(x)*period_adv*(deltasensible(x))**e
If I impose
m=3.8
e=0.5
and just plot the function g(x) superimposed on the data it seems to work pretty well.
However if I try to fit it using the parameters
fit g(x) './advection_da_1p0.txt' using 5:2 via m,e
I get the following error
iter chisq delta/lim lambda m e
0 4.2471983038e+00 0.00e+00 5.51e+00 3.800000e+00 5.000000e-01
1 3.7149813491e+00 -1.43e+04 5.51e-01 3.573384e+00 4.843345e-01
Current data point
=========================
# = 8 out of 8
x = 0.0178156
z = 0.0309726
Current set of parameters
=========================
m = 0.0178156
e = -0.0583802
"rain_estimate.gpl", line 52: Undefined value during function evaluation
For some reason Gnuplot is trying out really strange values for m,e, although I provided their initial values. If I remove the deltalatent(x) dependency everything is working fine. Am I missing something simple?
So I think I figured it out the problem by myself. Given my data a line was the best fit for Gnuplot so that it was trying to remove the exponential dependency on deltasensible by choosing a really small coefficient. Seems more an "error" with the data than with Gnuplot itself.

Resources