Generate heatmap using Pandas and Weasyprint - html

I have a pandas data frame , which I am trying to render as a PDF using Weasyprint. For other formatting changes , I have used 'column formatters' and modified the underlying HTML.
int_frmt = lambda x: '<div style="text-align:right">%s</div>' % '{0}'.format(int(round(x)))
frmt = {col: int_frmt for col in df.columns if df.dtypes[col] in [np.dtype('int64'), np.dtype('float64')]}
How can I add a Heatmap to the PDF in the same manner ( by modifying the underlying HTML )?
One way of doing this, which I could think, is to generate a separate pandas dataframe which contains all the color information, and then superimpose the two frames by iterating over all the values and modifying each cell individually.
I am looking for a more direct and comprehensive solution, or an API, of the like we have in Matplotlib, Seaborn ( heatmap() function ).
Thanks a lot.

Related

In python-tkinter export images name to csv file

I am trying to build a pygame editor with python and tkinter.
I have this situation: on a tkinter canvas I can place tiles neatly and without overlapping (see attached image, tiles are taken from Ghosts 'n Goblins).
Now I would like to export what is displayed on the canvas to a csv file:
for instance, if in a particular cell there's no image I would like to export "-1" to the csv file;
if in the cell nearby there's an image (let's say 1.png) I would like to export "1" to the csv;
if the image displayed is "2.png" I would like to export "2" and so on.
I am able to open a csv file and write on it but I cannot retrieve the information I need from Tkinter.
I think I could use some kind of a for loop but I do not know where to start.
I've tried:
img_on_grid = []
def export_csv():
for row in range(8):
test_1=canvas.itemcget("image_B", "image")
img_on_grid.append(test_1)
print(img_on_grid)de here
but it doesn't work: it repeats the id item.
Any help will be appreciated.

Keras Data Generator, show generated input and output

I implemented an own simple datagenerator based on https://stanford.edu/~shervine/blog/keras-how-to-generate-data-on-the-fly
My datagenerator uses as input and as output images.
Now I want to see the images, which the generator will use.
Does anyone know, how to get them?
datagen = DataGenerator(ids_training, input_dir, output_dir, **params)
X,y = datagen.next()
The datagen.next() doesn't work. I get the error "'dataGenerator' object has no attribute 'next'"
Thanks in advance!

Creating gallery-like plots in HTML from R Markdown

I am working on a data analysis project in R. In the end I need to hand in an HTML document.
I created a couple of PCA biplots using the autoplot funciton, about like this:
autoplot(pca, data = expression, x = 1, y = 2)
#pca is a prcomp element and expression is a data frame
By now, they are plotted one below the other in the HTML document. Is there a function that allows me to click through the different plots? So that only the first plot is shown and by clicking on an arrow or something, the second plot is shown in the same place? Kind of like a gallery.
The way multiple plots from the same chunk are show in an R Markdown would be even better, so you can select one specific plot by clicking on a miniature version of it
I've been looking through the internet a lot and hoped to find something from the html widgets page, but couldn't find anything after all.
I would really appreciate your help on this. Thanks :)
EDIT: I am not sure whether I am allowed to hand in a shiny applet, so being able to do it solely in the HTML would be awesome
Right, I found a way to do it that works fine for me. I used the {.tabset} argument I found at this link:
https://bookdown.org/yihui/rmarkdown-cookbook/html-tabs.html
## Results {.tabset}
### PC1-PC2 biplot
autoplot(pca, data = expression, x = 1, y = 2)
### PC1-PC3 biplot
autoplot(pca, data = expression, x = 1, y = 3)
## {-}
To use this, you have to create headers in your markdown using the # symbol. All headers that are one "level" below the one to which you added the {.tabset} argument (i.e. that have one more # symbol) will be the names of your tabs.
To close the tab section, you use the same number of # symbols you used in the header behind which you wrote the {.tabset} argument and write {-}.

THREE.js - morphTargetInfluences on an imported JSON mesh not getting results

I have a basic three.js scene in which I am attempting to get objects exported from Blender (as JSON files with embedded morphs) to function and update their shapes with user input.
Here is a test scene
http://onthez.com/temphosting/three-js-morph-test/morph-test.html
The slab is being resized without morphs by simply scaling a box, which is working just fine.
I must be missing something fundamental with the little monument on top. It has 3 morphs (width, depth, height) that are intended to allow it to resize.
I am using this code to implement the morph based on users dat.gui input.
folder1.add( params, 'width', 12, 100 ).step(1).name("Width").onChange( function () {
updateFoundation();
building.morphTargetInfluences['width'] = params.width/100;
roofL.morphTargetInfluences['width'] = params.width/100;
roofR.morphTargetInfluences['width'] = params.width/100;
building.updateMorphs();
});
The materials for building, roofL, and roofR each have morphTargets set as true.
I've been going over the three.js examples here:
http://threejs.org/examples/?q=morph#webgl_morphtargets_human
as well as #webgl_morphtargets and #webgl_morphtargets_horse
Any thoughts or input would be much appreciated!
I believe I've reached a solution for my question I was under the impression that the JSON loader was preserving the morph target names to be used in place of an index number with morphTargetInfluences
something like morphTargetInfluences['myMorphTargetName']
but, after closer inspection in the console it seems like they should be referred to by number like morphTargetInfluences[0]
Not the most intuitive, but I can work with it.

Stick Images together

I just tried to use Google Map Buddy to get satellite image from Google Map. This application first download small images from google map and then stick them together into new image. I had to wait about 2 hours to get images download my computer and it looks like it downloaded all images (22,194 images) but then the app told me that it cannot stick them together. When I started app again I though this app will reuse images on my comp but it start downloading them again. So I had to stop the process and ask you, guys, if you know how I can put that puzzle together.
The naming pattern of those images goes like this:
x=92651y=48130zoom=17.png
x=92652y=48130zoom=17.png
x=92653y=48130zoom=17.png
x=92654y=48130zoom=17.png
x=92655y=48130zoom=17.png
...
...
x=92664y=48131zoom=17.png
x=92665y=48131zoom=17.png
x=92666y=48131zoom=17.png
x=92667y=48131zoom=17.png
...
...
x=92689y=48132zoom=17.png
x=92690y=48132zoom=17.png
x=92691y=48132zoom=17.png
x=92692y=48132zoom=17.png
x=92693y=48132zoom=17.png
What can I do to stick them together programmatically using some simple scripting language? I have access to Mac and Windows systems and may be can install any simple scripting languages.
Thanks
You could use Python with Python Imaging Library (PIL).
First I'd make a list of filename and their coordinates. Extract the integer coordinates from the filenames with regular expressions and store them in a list of dictionaries:
>>> filename = 'x=92664y=48131zoom=17.png'
>>> imagePattern = re.compile(r'^x=(\d{5})y=(\d{5})zoom=17.png$')
>>> x,y = map(int, imagePattern.search(filename).groups())
>>> {'x':x, 'y':y, 'filename':filename}
{'y': 48131, 'x': 92664, 'filename': 'x=92664y=48131zoom=17.png'}
Having a list of dictionaries enables you to sort them according to either dimensions:
tileListSortedByX = sorted(tileList, key = lambda i: i["x"])
and also filter them:
fileListWhereX48131 = [tile for tile in tileList if tile["x"]==48131]
With these two operations you can easily imagine the for loops to iterate over tiles line by line.
The last thing you need to create a big empty image (with PIL) where you'll paste the small tile images into. Its size will be a multiple of the tile size.
>>> from PIL import Image
>>> bigImage = Image.new('RGB',(300,300),(255,255,255))
#creates a white 300x300 image
Pasting the small images into the big one looks like this:
>>> smallImage = Image.open(tile["filename"])
>>> bigImage.paste(smallImage,(0,0))
Hope you get the idea.
The process of "sticking images together" is usually called "stitching" or "mosaicing".
I found a list of many applications that do this on Wikipedia article - "Comparison of Photo Stitching Applications".
Edited: removed link to single app I found and replaced with wikipedia list of software.