I see in the troubleshooting guide to Altair that:
'If you are working in a notebook environment, the chart is only
displayed if the last line of the cell evaluates to a chart object'
I have a dictionary of several auto-generated altair charts. I want to show in one notebook cell, separately, all the charts I have created. I would like to do something like:
for k in graphs:
graphs[k].show() #or the equivalent of 'show this chart'
How can I do the equivalent of this? Currently I can only render a single chart in a cell by evaluating a single chart.
Use chart.display():
for k in graphs:
graphs[k].display()
Related
I am using httpgd as the default graphic devide for R in vs code.
if I don't use dev.list(), it will open up new plots in the same tab everytime a new plot is generated.
If I use dev.list(), it will open up a separate tab for the new plot. But how do I close the tab which stores previous plots?
Thanks.
In org-mode, I can name the output of a code block and include it elsewhere in the document.
Is it possible to do this (or something similar) in a colab .ipynb file, or within a Jupyter notebook in general?
For example, I can make a cell with some Python code that generates a plot:
import matplotlib.pyplot as plt
plt.plot([0,2,1,4,9])
After executing, the plot appears below the code cell. So far so good.
But how do I capture this plot and to use it elsewhere in the notebook?
My hope is there is some syntax so that I can include the plot in a markdown cell, for example:
# this is my title
As you can see, the numbers go up and down in the plot:
![][some_magic_link_here]
Here is some more text to explain the plot.
Does such a feature exist in colab?
Good news - embedding an image in another markdown cell is self-service. Here's an example:
Full notebook:
https://colab.research.google.com/drive/1PF-hT-m8eZN2CBzFkMp9Bvzj9pSBQVYn
The key bits are:
Using IPython.display.Markdown is order to programmatically construct the markdown.
In addition to rendering, save the matplotlib figure using savefig.
Include the image data in the markdown after base64 encoding.
I need to generate about >50 plots. I want to save them all in one pdf and have just a few of them appear in my R markdown html output.
I can print many plots to a single pdf like this:
pdf("path/to/out.pdf")
for (sam in samples){
plot(sam) # simplified stand-in for many lines of code
}
dev.off()
That puts one sample's plot on each page of a pdf that I can flip through later.
I want some of those plots to appear in my markdown, without duplicating the plot code.
I've tried:
pdf("path/to/out.pdf")
count=0
for (sam in samples){
plot(sam) # simplified stand-in for many lines of code
if (sample(1:10,1)==1){ #randomly select a few examples
count = count + 1
dev.copy(which=dev.prev()) # to revert back to the default device
dev.set(dev.next()) # to resume printing to the same pdf
}
}
dev.off()
With this, the pdf is correct and count is >0, but the plots do not appear in the markdown report.
I think something from the dev.copy() family will do what I want but I can't seem to make it work. In other variants I tried, dev.print() complains about only printing from a screen device, or I get errors saying that I cannot copy to the same device, or cannot copy to a null device.
Similar questions (such as Saving plot as pdf and simultaneously display it in the window (x11)) often want to do the reverse: print to screen a then to a pdf. And they generally only deal with one plot.
I want to make several plots, and I want ALL of my plots to go to the pdf, but only a FEW to go to the Rmarkdown html report as an example of what is in the pdf.
I'm working on a mac using R 3.5.1, RStudio v1.1.456
Thanks in advance!
When editing an R notebook inside RStudio, if I create multiple graphical outputs in one R block, I get an icon for each plot, which I can click on to select which plot to look at:
I like that behavior, it's especially handy to click from one plot to another to compare changes between them.
However, when I render the notebook to HTML (e.g. by hitting the "Preview" button in the editor), the plots simply cascade down the page:
Is there a way I can get the former behavior in an exported document? Some option I can set, or a chunk of Javascript I can include, or something?
I just started using R in Jupyter notebook. There seems to be some issue displaying tibble table.
for example,
mtcars
Everything is normal.
If mtcars is converted to tibble,
car<-as_data_frame(mtcars)
car
The table displayed is totally screwed....
Anyone knows why? Do I need to set some options in jupyter notebook?
A follow-up question: How to control the number of rows for table output (not using head())? Is there any notebook options I can set? Is there any way that display the whole table with some page number button like those in R notebook?
Are you sure that you are using the latest version of Jupyter Notebook? I get exactly the same printout for the base data frame and the tibble.
As for the number of rows to show, I don't know of any notebook setting. If you don't want to use head(), you can always do:
mtcars[seq.int(15),]
with whatever number of lines you want instead of 15.