I'm trying to rotate the y axis label of a plot:
function contour(k::Real, a::Real = 6.0, y::Real = 12.0)
y^2 / ((a^2) * k)
end
K_contour = range(0.5, stop = 8, length = 1000)
plot(K_contour, contour, xaxis = ("K", (0, 8)),
yaxis = ("L", (0,8)),
label = "",
)
I get the following:
I'd like to rotate the "L" 90 degrees. I can't find the appropriate axis attribute for this - can anyone help?
As mentioned in this julia forum answer you need to use pyplot backend and yguidefontrotation=-90 parameter:
pyplot()
plot(K_contour, contour, xaxis = ("K", (0, 8)),
ylabel = "L", ylims=(0,8), yguidefontrotation=-90,
label = "",)
Related
I would like to have a double y-axis in one of my subplots; however, it seems like I am missing something about twinx() and link = :x, but I couldn't figure out what..
Plotting double y-axis using twinx() works fine in a standard plotting frame. However, it creates the following problem when I try to link the x-axes. What am I missing here?
using Plots
x = [3, 5, 7, 9];
y = [10, 20, 30 , 40];
z = [-10, -20, -30, -40];
a = plot(1:10, color = :black, legend = false)
b = plot(x, y, color = :green, legend = false)
b = scatter!(twinx(), x, z, color = :orange, legend = false)
plot(a, b, layout = (2, 1), link= :x)
Output:
Thank you very much!
Sometimes there is a need to display points on the graph on top of the axes so that the result looks something like this:
Previously, when I used R, it took a certain amount of alchemy to get the desired result: first the size of the rendering field was set, then the position of the axis, and at the end data points were drawn on top of all this:
f <- rnorm(10, mean=5, sd=1)
plot(x = f, y = c(rep(0, 10)), xlim = c(-1, 11), ylim = c(0, 1),
axes = FALSE, box = FALSE, xaxs = "i", ylab="")
abline(h=0)
axis(side = 1, at = seq(0, 10, 2), pos = 0, tck = -0.02)
points(x = f, y = c(rep(0, 10)), cex=1.0, pch = 21,
col="black", bg="white", lwd = 1)
Now I'm trying to translate my entire workflow to Julia and I want to find some alternative for such visualization. I usually use Plots.jl with GR backend. The trick I used in R does not work in this case: when adding a layer above, it is still cut off by the canvas borders set at the beginning:
c = vcat(1.0, 3.0, 4.0, 6.0, 7.0, 9.0, 12.0, 21.0)
plot(c, zeros(length(c)), seriestype = :scatter,
markersize=5, markershape=:circle, color = :white, label = "", ylims=(0,Inf))
plot!(c, zeros(length(c)), seriestype = :scatter,
markersize=5, markershape=:circle, color = :white, label = "")
Result:
What is the most rational way to get such graphics with Julia?
You should be able to plot on the x-axis by using framestyle=:origin or framestyle=:zerolines
scatter(c, zeros(length(c)),
markersize=5, markershape=:circle,
color = :red, label="", framestyle=:zerolines)
and if you want to show just the x-axis
scatter(c, zeros(length(c)), markersize=5,
markershape=:circle, color = :red, legend=false,
framestyle=:origin, yaxis=false, grid=false, aspect_ratio=1.0)
I'd like to plot a function f(x,y,z) in xyz-space by HeatMap.
I have the following code by https://lazarusa.github.io/BeautifulMakie/surfWireLines/RGBcube/ .
using GLMakie, GeometryBasics, Colors
positions = vec([(i, j, k) for i=1:L,j=1:L,k=1:L]) #3D coordinate
F = zeros(Float64,length(positions)
for i = 1:length(positions) #convert f(x,y,z) to an array
x = positions[i][1]
y = positions[i][2]
z = positions[i][3]
F[i] = f(x,y,z)
end
fig, ax = mesh(HyperRectangle(Vec3f0(positions[1]...),Vec3f0(0.8)), color = RGBA(0,0,F[1],0.5), transparency = false) #HyperRectangle(::position,::length),color=(::red,::green,::blue,::alpha)
wireframe!(ax,HyperRectangle(Vec3f0(positions[1]...), Vec3f0(0.8)), linewidth = 0.1, overdraw = false)
for i in 2:length(positions)
mesh!(ax, HyperRectangle(Vec3f0(positions[i]...), Vec3f0(0.8)), color = RGBA(0,0,F[i],0.5))
wireframe!(ax, HyperRectangle(Vec3f0(positions[i]...), Vec3f0(0.8)), linewidth = 0.1, overdraw = false)
end
fig
This code has mostly helped, but there's still a little problem.:
How to move the camera? (update_camera! needs Scene, but ax is LScene. I don't know what this is.)
How to adjust the axis (labels, ticks, etc.)?
How to add the colorbar?
How to save the figure?
again.
I did another example. This one is really fast. There, you have most of the options you want.
https://lazarusa.github.io/BeautifulMakie/surfWireLines/volumeScatters/
For custom ticks, you can always do
ax.xticks = ([1,2,3], ["1","2", "3"])
also, consider joining https://discourse.julialang.org, there more people could help, much much faster.
Complete code here as well.
# by Lazaro Alonso
using GLMakie
let
x = 1:10
y = 1:10
z = 1:10
f(x,y,z) = x^2 + y^2 + z^2
positions = vec([(i, j, k) for i in x,j in y, k in z])
vals = [f(ix,iy,iz) for ix in x, iy in y, iz in z]
fig, ax, pltobj = meshscatter(positions, color = vec(vals),
marker = FRect3D(Vec3f0(0), Vec3f0(10)), # here, if you use less than 10, you will see smaller squares.
colormap = :Spectral_11, colorrange = (minimum(vals), maximum(vals)),
transparency = true, # set to false, if you don't want the transparency.
shading= false,
figure = (; resolution = (800,800)),
axis=(; type=Axis3, perspectiveness = 0.5, azimuth = 7.19, elevation = 0.57,
xlabel = "x label", ylabel = "y label", zlabel = "z label",
aspect = (1,1,1)))
cbar = Colorbar(fig, pltobj, label = "f values", height = Relative(0.5))
xlims!(ax,-1,11)
ylims!(ax,-1,11)
zlims!(ax,-1,11)
fig[1,2] = cbar
fig
#save("fileName.png", fig) # here, you save your figure.
end
How to add a superscript or a subscript to an axis label to a 3D plot in plotly?
I tried to use bquote, but it did not work. Googling did not bring much on the matter either.
Scavenged code:
library(plotly)
set.seed(123)
n <- 100
theta <- runif(n, 0, 2*pi)
u <- runif(n, -1, 1)
base<-'B1'
compare<-'A1'
plot (1, 1, main = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n' ~.(compare)~ 'minus'~.(base)))
p <- plot_ly(x = ~sqrt(1 - u^2) * cos(theta), y = ~sqrt(1 - u^2) * sin(theta), z = ~u) %>%
layout(
title = "Layout options in a 3d scatter plot",
scene = list(
xaxis = list(title = bquote('Annual mean' ~CO[2] ~'Flux Difference: \n' ~.(compare)~ 'minus'~.(base))),
yaxis = list(title = "Sin"),
zaxis = list(title = "Z")
))
p
Thank you for your time!
With HTML tags, for example:
yaxis = list(title = "Sin<sup>super</sup>")
More info here. Hope this helps!
I use scatterplot3d to plot 3D with R. The orientation of the y-axis label bothers me because it is vertical and not parallel to the y-axis.
Is there a way to rotate the label and adjust its angle? Unfortunately, I didn't finde anything in the documentation.
If you don't have to draw many plots and are willing to adjust values manually, you can pass ylab = "" when making the 3d scatter and then add text later on with appropriate srt value. srt allows you to rotate text at desired angle. Note that x and y when adding text is different from x and y of 3d scatter.
set.seed(42)
scatterplot3d(rnorm(20), rnorm(20), rnorm(20), ylab = "")
text(x = 5, y = -2.5, "Y-axis", srt = 45)
Using scale.y
set.seed(42)
scatterplot3d(rnorm(20), rnorm(20), rnorm(20), ylab = "", scale.y = 2)
text(x = 6.5, y = -1.5, "Somewhat longer Y-axis", srt = 45)