I wrote this code for thinking of one chart with two lines. But it showed up with two separate charts. Any ideas?
LA_Temp=df.plot(x="Years",y="LA_avgtemp Yr")
df.plot(x="Years", y="LA_MA 10 Yr")
Try instead:
ax = df.plot(x="Years",y="LA_avgtemp Yr")
df.plot(x="Years", y="LA_MA 10 Yr",ax=ax)
If that doesn't work, you may have a non-standard matplotlib set-up.
You need to use the ax parameter in pandas.dataframe.plot.
Use on the first df.plot to grab a handle on that axes:
ax = df.plot(x="Years",y="LA_avgtemp Yr")
then on subsequent plots use the ax parameter.
df.plot(x="Years", y="LA_MA 10 Yr", ax=ax)
Related
using Plots
plot(0:10,sin);
plot!(0:10,sin,seriestype = :scatter)
In this example, the output are actually two plots. How can I save them in one file?
I searched and tried some method, but they only support one single plot and I haven't found any functions for multiple plots.
This is just one figure - plot! (with a bang) mutates the figure object created in the first plot call.
Saving this is as simple as savefig("my_output.svg") - if this does not work as expected please provide more details.
Not directly related, but seeing that you are overlaying a scatter plot onto a line plot you might be interested in the linetype kwarg:
plot(0:10, sin, linetype = :scatterpath)
plot(0:10, sin, lt = :scatterpath) # short form alias
will both produce a line and scatter at the same time (with a single label and single colour).
I want to plot 1:3 using points but 3:-1:1 using lines.
How do I achieve this with Plots.jl?
Plot one thing first and then use a new plot command with a bang to modify the previous plot.
scatter(1:3)
plot!(3:-1:1)
I'm trying to add multiple TA's to my main chartSeries chart, and they all add below instead of overlaying each other. Is it possible to add multiple TA overlays?
chartSeries(GE, theme="white",
TA="addTA(GE1);addTA(GE2);addTA(GE3)")
I've tried with the variables below;
on=1 and
overlay=TRUE
I'm looking for all the TA's to be in a single chart.
Thank you in advance for your time.
Well, on=1 is what you need. I'm having trouble getting the TA="" to work, with the data I had to hand, but this did work:
chartSeries(x,TA=NULL);addTA(EMA(x$Close),on=1)
(The TA=NULL is to remove the volume chart.)
Or, use newTA to define your TA with all the desired parameters in advance, and then the TA argument does accept it:
myEMA = newTA(EMA, Cl, on=1, col=7)
chartSeries(x, TA="myEMA()")
(See ?newTA, which is where I stole that first line from!)
I have two plots and I want to add some additional lines to both plots. Is there a way in R to choose the plot (among the two) to draw the new lines?
Edit1:
Actually I have multiple plots in one window using mfrow
Edit2:
I have edited the the question to include the problem i faced after using mfgin par()
x=1:10
y=seq(10,100,10)
z=seq(100,1000,100)
par(mfrow=c(2,1))
plot(x,y)
abline(a=0,b=10,col="blue")
plot(x,z)
abline(a=0,b=100,col="blue")
which gives
But when I use
x=1:10
y=seq(10,100,10)
z=seq(100,1000,100)
par(mfrow=c(2,1))
plot(x,y)
plot(x,z)
par(mfg=c(1,1))
abline(a=0,b=10,col="blue")
par(mfg=c(2,1))
abline(a=0,b=100,col="blue")
the result is
Note the false behavior of the first abline
Can anyone explain the reason and a solution for this?
Assuming you have multiple graphics windows open, you want to use the dev.cur(), dev.next(), dev.set(), dev.list() functions (see ?dev.cur) to identify the current graphics device and switch among devices.
If on the other hand you have set up multiple plots within a single window via the mfrow or mfcol parameters to par(), you can use par("mfg") to query/set which plot is current.
If you use layout, lattice, ggplot2, or raw grid graphics, I'm not sure.
How I can remove the legend in a plot in R? I tried legend<-FALSE, doesn't work.
Also, is there a better way to set the position of the legend? For example, is there
a way I can pick the location with my cursor? And I am not talking about ggplot or any fancy add-ons, just regular R plotting.
In order:
This is related to what people tried to explain to you yesterday: Think of a script as primary means of creating your R session. In ESS, you get the script as a by-product; in RStudio you can also work with commands first and then pass those to your session. Lastly, no you can't remove a legend which has already been added to a plot, but you can hopefully re-create your graph using the saved commands.
Yes, since Duncan Murdoch added support for 'topleft' etc you can use logical commands:
plot(1:10) # simple plot
legend("bottomright", "foo") # 'foo' in bottom-right corner
Yes, if you use the output of locator() as input for the legend() command.
You need to specify which plotting function is producing the legend. (Most plotting function do not plot legends by default.)
There is a locator function.