I have a problem about the plot data on juno using pyplot.
using PyCall
using PyPlot
x = linspace(0,2*pi,1000); y = sin(3*x + 4*cos(2*x))
plot(x, y, color="red", linewidth=2.0, linestyle="--")
After I did "eval all" in Juno, nothing happened.
Is there a solution in solving this problem?
thanks
plotwill only return a vector of PyObjects.
To display the figure interactively in Juno use gcf() (get current figure).
Related
I would like to make a custom legend in Julia's pyplot, in which the legend labels are not necessarily related to individual series plotted on the graph. For example:
In Python (pyplot comes from matplotlib) this could be done with:
from matplotlib.lines import Line2D
custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),
Line2D([0], [0], color=cmap(.5), lw=4),
Line2D([0], [0], color=cmap(1.), lw=4)]
fig, ax = plt.subplots()
lines = ax.plot(data)
ax.legend(custom_lines, ['Cold', 'Medium', 'Hot'])
The issue is I cannot seem to access the Line2D object in pyplot (using pyplot as plt, plt.lines.Line2D does not work).
Any workaround?
I know it is not pyplot but MakieLayout will solve your problem:
Link to the example with code.
I got the answer from Julia Discourse.
I wasn't satisfied with the existing answer, but I managed to figure it out. Per the PyPlot.jl docs under Exported Functions,
(And the raw PyObject for the matplotlib modules is also accessible as PyPlot.matplotlib.)
So you can achieve your goal by just putting the full call in (I assign to a variable to avoid making the custom_lines ugly):
L2D = PyPlot.matplotlib.lines.Line2D
custom_lines = [L2D([0], [0], color=cmap(0.), lw=4),
L2D([0], [0], color=cmap(.5), lw=4),
L2D([0], [0], color=cmap(1.), lw=4)]
fig, ax = plt.subplots()
lines = ax.plot(data)
ax.legend(custom_lines, ['Cold', 'Medium', 'Hot'])
using Gadfly
xvalues = rand(1000);
yvalues = rand(1000);
Gadfly.plot(x=xvalues,y=xvalues,Geom.point,Geom.line)
I am trying make a plot using julia Gadfly package in the atom editor . it does display any plot in the plot panel
This should have been fixed by GiovineItalia/Gadfly.jl/pull/1373 (in Gadfly v1.2). What version of Gadfly do you have?:
julia> ]st Gadfly
If you have an older version, try doing popdisplay(), and redoing the plot.
I tried following the official Julia docs on plotting, where the following code is proposed for plotting:
Pkg.add("PyPlot")
using PyPlot
x = range(0,stop=2*pi,length=1000); y = sin.(3*x + 4*cos.(2*x))
plot(x, y, color="red", linewidth=2.0, linestyle="--")
Julia v1.0.2 exits with the error
ERROR: LoadError: UndefVarError: Pkg not defined
My question is how to actually run the above code?
The problem is that the Pkg module is not loaded, because this seems to be deprecated. To fix this the following line has to be added before the first line
using Pkg
The code then works for me not from the command line interface, but within an interactive julia session and produces the following image:
Using Julia 0.3.10 with Juno as IDE and Gadfly latest one. Tried running a sample code, but got stuck with add_plot_element not defined error message. The last line throws the error. Running on Win8 64bit. I'm sure I'm missing something.
using Gadfly
xs = [0:0.1:pi]
k = layer(x=xs, y=sin(xs))
p = plot(x=xs, y=sin(xs))
add_plot_element(k, Guide.title("Now it has a title"))
First, add_plot_element is modifying, so you need the ! like:
add_plot_element!(k,Guide.title(...))
This function is also not exported from Gadfly, so you would really need to write:
Gadfly.add_plot_element!(k, Guide.title("Now it has a title"))
except add_plot_element! doesn't work on Gadfly layers! It does, however, work on plots. What should work:
Gadfly.add_plot_element!(p, Guide.title("Now it has a title"))
since the layer itself doesn't have Guide.Title elements, but the plot does.
I have the scatterplot3d package installed in R. When I load it with library(scatterplot3d) or require(scatterplot3d) I am able to create a 3d scatter plot. However, when I try to use the points3d function I get the following error:
Error: could not find function "points3d"
I tried reinstalling the package to no avail (both inside R and as a tarball using R CMD INSTALL in the command line). I am running Xubuntu 12.10 kernel 3.8.7-030807-generic and R version 2.15.3 (2013-03-01).
Entering locate points3d in the command line gave me no results.
I also tried the par.mar default settings command as explained in the manual.
scatterplot3d does an interesting object-oriented twist on the usual R practice. The object returned from the function call includes the points3d function as built-in part of the object but it is not in the Global environment. It is intended that you add to the existing plot-object using that "attached" function that is not a free-living organism but rather a domesticated animal that only exists in the object corral, so you would use this as your syntax:
object$point3d(x,y,z)
I do "feel your pain" but can show you how to overcome the frustration, since I created a working example yesterday: Using scatterplot3d to plot a sphere
You need to intall the package plot3D in the usual way via
install.packages("plot3D")
Then you just need to import, generate the dataset and use the function points3D()
library(plot3D)
x = rnorm(100)
y = rnorm(100)
z = x + y + rnorm(100,0,1)
points3D(x, y, z, col = rainbow(1000))
This is the plot generated by the code above