Change values on the x and y axis - zedgraph

Right now the values on both x and y axis are starting from 0, 0.1, 0.2 ..., 1, like seen on the image. The problem is that my graph is starting to draw when x = 3, so I cannot see it, since x only goes to 1. Is it possible to change what values are shown on the 2 axis?
So fx. to have the values go like 100, 200, 300, ..., 900, etc? Cus there will be situations where I will need the x and y values to be large

I'm not sure if I understand your question correctly.!
If you want to change the X Axis Min/Max value, try this..
ZedGraph.GraphPane myPane = zedGraphControl1.GraphPane;
myPane.XAxis.Scale.Min = 10.0;
myPane.XAxis.Scale.Max = 100.0;
myPane.AxisChange();
zedGraphControl1.Refresh();

Related

numerical approximation 2D integral

I want to approximate numerically integral in the 2 D rectangular domain.
D = [0, 10] X [0, 10]
enter image description here
I know we can approximate integral with a double sum for x and y. We need to divide domain my subdomains.
x bar and y bar are the values in the center of each subdomain.
My function is represented numerically.
I know my value of function f(x, y) for every pair (x, y), but I don't know how to find function values in pair (x bar and y bar)
x1, x2 = np.meshgrid(np.linspace(0, 10, 100),np.linspace(0, 10, res))
xx = np.vstack([x1.ravel(), x2.ravel()]).T
f = KL._eigenfunctions[0](xx) #this is just the class KL that can find the value of function
This is how my function looks like in 2 D domain: enter image description here

Adding specific range for y axis to plot

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))

Matplotlib - Correlation plots with different range of numbers but on same scale

I would like to have a 2 by 3 figure with 6 correlation plots, sharing the same scale, even when the values in the plots have different ranges. Below you can see what I have so far.
In the first column, the values range from 0 to 1, with 1 on the diagonal, and close to 0 elsewhere. For the other two columns it holds for the top row that the values range from 0 to 1, whereas the values in the bottom row range from -1 and 1. The difference between the second and third column is that the values in the second column are around 0.3 (and -0.3) and the values in the third column are around 0.7 (and -0.7).
As you can see, several things seem to be going incorrect. First of all, although I want them all to be plotted according to the same color scale, with dark blue being -1 and yellow being 1, this is clearly not the case. If this would hold, we would have bright blue/greenish in the first column. What could I do to indicate the range for the colors? Next, how do I change the labels of the color scale on the right? I would like it to range from -1 to 1.
Below, you find my implementation.
fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(15,8))
idx_mixed = {False: 0, True: 1}
idx_rho = {0: 0, 0.3: 1, 0.7: 2}
for mixed in [False, True]:
for rho in [0, 0.3, 0.7]:
ax[idx_mixed[mixed]][idx_rho[rho]].matshow(results[mixed][rho])
ax[0][0].set_title("No correlation", pad=20, fontsize=14)
ax[0][1].set_title("Weakly correlated", pad=20, fontsize=14)
ax[0][2].set_title("Strongly correlated", pad=20, fontsize=14)
ax[0][0].set_ylabel("Positive correlations", fontsize = 14)
ax[1][0].set_ylabel("Mixed correlations", fontsize = 14)
fig.colorbar(mpl.cm.ScalarMappable(), ax=fig.get_axes())
You need to provide a norm= argument to matshow() so that the data is scaled to the range [-1, 1] rather than a range defined by the min and max value present in the data. See Colormap Normalization for more details.
cmap = 'viridis'
norm = matplotlib.colors.Normalize(vmin=-1, vmax=1)
fig, axs = plt.subplots(2,3)
for ax, d in zip(axs.flat, data):
m = ax.matshow(d, cmap=cmap, norm=norm)
fig.colorbar(m, ax=axs)

How to show axis ticks corresponding to plotted datapoints in a seaborn plot?

I am using seaborn to plot some values which are numerical. But the each of those numbers correspond to a textual value and I want those textual values to be displayed on the axes. Like if the numerical values progress as 0, 5, 10, ..., 30; each of those encoded numbers must be linked to a textual description. How can I do this?
Main Point:
Use:
ax = plt.gca()
ax.set_xticks([<the x components of your datapoints>]);
ax.set_yticks([<the y components of your datapoints>]);
More elaborate version below.
You can go back to matplotlib and it will do it for you.
Let's say you want to plot [0, 7, 14 ... 35] against [0, 2, 4, ... 10]. The two arrays can be created by:
stepy=7
stepx=2
[stepy*y for y in range(6)]
(returning [0, 7, 14, 21, 28, 35])
and
[stepx*x for x in range(6)]
(returning [0, 2, 4, 6, 8, 10]).
Plot these with seaborn:
sns.scatterplot([stepx*x for x in range(6)],[stepy*y for y in range(6)]).
Give current axis to matplotlib by ax = plt.gca(), finish using set_xticks and set_yticks:
ax.set_xticks([stepx*x for x in range(6)]);
ax.set_yticks([stepy*y for y in range(6)]);
The whole code together:
stepy=7
stepx=2
sns.scatterplot([stepx*x for x in range(6)],[stepy*y for y in range(6)])
ax = plt.gca()
ax.set_xticks([stepx*x for x in range(6)]);
ax.set_yticks([stepy*y for y in range(6)]);
Yielding the plot:
I changed the example in the OP because with those numbers to plot, the plots already behave as desired.

Python plot_surface set Y limits to center at 0

I'm using cylindric coordinates, created a meshgrid and tried to plot using plot_surface. My full dataset doesn't get properly drawn because the scaling on the Y-axis is not correct.
I'm trying to plot the magnetic field values versus Z and P(rho) values. Z can be both negative and positive. P(rho) can only be positive.
The problem is that p (Y-axis) always starts from 0 to 10 (giving 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) whereas I'd like to have it like: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 so that its centered at 0.
So this is my example code. I won't add the calculations for the magnetic field. These are not relevant for this issue.
fig = plt.figure()
ax = Axes3D(fig)
# Define the plane over which fields are computed.
# N must be odd to include the point (0,0).
M = 26 # No. of points along the rho axis.
N = 51 # No. of points along the z axis.
p1 = np.linspace(0, a, M)
p = np.concatenate([p1[::-1][:-1], p1]) # Make it symmetric.
z = np.linspace(-d, d, N)
p, z = np.meshgrid(p, z) # Create grid of (p,z).
# CALCULATE magnetic field bt. So assume this is done here...
bt = np.sqrt(np.power(bz, 2) + np.power(bp, 2))
ax.plot_surface(z, p, bt, cmap=plt.cm.YlGnBu_r)
plt.show()
So when making adding the line,
p = np.concatenate([p1[::-1][:-1], p1])
the dimensions are broken and plot_surface is rightfully complaining. I'd expect this line would center the 0 in the middle of the array.
Thanks.