I am creating charts with origin(100,0) i.e, x axis value=100. At first I used,
ActiveChart.Axes(xlValue).MajorUnit = 10
and I got the x axis ... 70,80,90,100,110,120,130....etc
I thought it would be better if I had axis values as ...60,80,100,120,140... etc. So I edited my code as follows,
ActiveChart.Axes(xlValue).MajorUnit = 20
But now I am getting ...70,90,110,130... etc.
How can I get my x axis as ...60,80,100,120,140...?
Related
I cannot work out how to apply a specific y axis range to my violin plot
current code is :
library(ggplot2)
X21$`gggnnn`<-as.factor(X21$`gggnnn`)
X21$`RTtype`<-as.factor(X21$`RTtype`)
bp<-ggplot(data=X21,aes(x=RTtype,y=RT,group=RTtype))+
geom_violin(aes(colour=RTtype),outlier.alpha = 1)+
facet_grid(.~gggnnn) +
labs(x="AM or PM", y='Reaction time /ms')+
geom_boxplot(width=0.1,colour="black",alpha=1,outlier.shape=4)+
ggtitle("AM and PM Reaction Time Distributions among Gamers and Non-gamers")+
geom_jitter(data=X21,aes(x=RTtype,y=RT,group=RTtype, colour=RTtype,shape=gggnnn))+
bp
this gives the plot as shown:
[1]:https://i.stack.imgur.com/3Aggm.png
I then tried to set y axis limits with adding a '+ylim(150,900)' , however this just truncated my data:
[2]:https://i.stack.imgur.com/kDiRs.png
I now see that this is a limit on the range of the data, not the values on the axis (i am looking for the y axis to go from 150 to 900, also i do not know how to change the y axis grid spacing, as it is currently in intervals of 250, which is harder to interperit, i would like to set this to 100.
I attempted to do this with '+scale_y_continuous(breaks = seq(150,900, by = 100))', However it had no effect on the plot
Any help would be much appreciated
datasheet format:
[3]: https://i.stack.imgur.com/iXKXF.png
in order to set y coordinate limits use
coord_cartesian(ylim = c(100,900))
generalised this is:
coordinates_cartesian(xlim = c(lower limit,upper limit), ylim( c =(lower,upper)
in order to set spacing use
scale_y_continuous(breaks = seq(100, 900, by = 200))
I have created a stacked bar plot using plotly.express. Each X-axis category has two correspondent Y-values that are stacked to give the total value of the two combined.
How can I add an individual error bar for each Y-value?
I have tried several options that all yield the same: The same value is added to both stacked bars. The error_y values are found in two separate columns in the dataframe: "st_dev_PHB_%" and "st_dev_PHV_%" , respectively, which correspond to 6 categorical values (x="C").
My intuition tells me its best to merge them into a new column in the dataframe, since I load the dataframe in the bar plot. However, each solution I try give an error or that the same value is added to each pair of Y-values.
What would be nice, is if it's possible to have X error_y values corresponding to the X number of variables loaded in the y=[...,...] . But that would off course be too easy .........................
data_MM = read_csv(....)
#data_MM["error_bar"] = data_MM[['st_dev_PHB_%', 'st_dev_PHV_%']].apply(tuple, axis=1).tolist()
#This one adds the values together instead of adding them to same list.
#data_MM["error_bar"] = data_MM['st_dev_PHB_%'] + data_MM['st_dev_PHV_%']
#data_MM["error_bar"] = data_MM[["st_dev_PHB_%", "st_dev_PHV_%"]].values.tolist()
#data_MM["error_bar"] = list(zip(data_MM['st_dev_PHB_%'],data_MM['st_dev_PHV_%']))
bar_plot = px.bar(data_MM, x="C", y=["PHB_wt%", "PHV_wt%"], hover_data =["PHA_total_wt%"], error_y="error_bar")
bar_plot.show()
The most commonly endured error message:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
I see your problem with the same error bar being used in both bars in the stack. However, I got a working solution with Plotly.graph_objs. The only downside was the second bar is plotting at the front, and therefore the upper half of the lower error bar is covered. At least you can still read off the error value from the hover data.
Here is the full code:
n = 20
x = list(range(1, n + 1))
y1 = np.random.random(n)
y2 = y1 + np.random.random(n)
e1 = y1 * 0.2
e2 = y2 * 0.05
trace1 = go.Bar(x=x, y=y1, error_y=dict(type='data', array=e1), name="Trace 1")
trace2 = go.Bar(x=x, y=y2, error_y=dict(type='data', array=e2), name="Trace 2")
fig = go.Figure(data=[trace1, trace2])
fig.update_layout(title="Test Plot", xaxis_title="X axis", yaxis_title="Y axis", barmode="stack")
fig.show()
Here is a resulting plot (top plot showing one error value, bottom plot showing different error value for the same bar stack):
The description of the data frame
When I try to find the relationship between budget and revenue_of_investment
x = dfm_2.budget
y = dfm_2.revenue_of_investment
plt.figure(figsize = (10,8))
plt.xlim((40000,42500000))
plt.scatter(x,y)
The output is:
I know the range of the budget is big, but I do not figure out the data on the x-axis.
I even set the range, however, the x-axis doesn't fit the data.
If I understand your question correctly (i.e. that the plot is not displaying all of the data on the x-axis), it's because your upper xlim is too small.
The maximum value of dfm_2.budget is 4.25 * 1e8 (i.e. 425000000), but your xlim upper limit is set to 4.25 * 1e7 (i.e. 42500000) (i.e. you're missing a zero in your plt.xlim())
I'd like to know how to find the value of the X axis, where the X and Y axes cross. The result is to be displayed in a cell. VB is optional.
Example
Where the arrow points is the value I would like to get.
From where the 60 in the Y axis crosses the points, I'd like to get the Y axis.
Here's my problem, I'm making charts with the windows.forms.datavisualisation.charting library in a vb.net program.
I want my charts' X axis to always be the same length (pixel wise) because I'm lining them up vertically. The charts all have the same width and the X axis values are always the same (hours from 0 to 24).
The thing is the Y labels are not all in the same format. Some are integer representing a mass, some are percentage... Which makes the strings in each Y axis labels of different length
For example:
Chart1 Y axis labels: 0, 1 000 000, 2000 000, ..., 10 000 000...;
Chart2 Y axis: 2.33%, 3.45%...
They all have the same font and I would like to keep it like that if possible, but the length of the X axis is more important.
Any ideas? The following charts should help to explain:
First chart
Second Chart