Creating a wordcloud with matplotlib - python

Im trying to create a wordcloud with Matplotlib. Essentially I am able to put text at arbitrary locations in my grid, but need to work out a way of preventing them from colliding. In relation to this I am stuck on two questions:
What is the unit of fontsize?
How do I transfer the "fontsize" of the text to units in my figure, so I can mark them as used? That is, how do I know how much space each letter will take up in my grid? Ideally I would not have to mark out a whole rectangle around each word, but only the pixels they actually use as available for other words.

I'm not sure about how to do it with matplotlib but I have used this in the past: http://peekaboo-vision.blogspot.co.uk/2012/11/a-wordcloud-in-python.html

Related

Is it possible in Python to create a custom made polygon and use that as arrow to produce a stream plot?

i want to create a plot with 13 different arrow styles for a vector field showing the stream of a sea. I want to use very specific arrows which are not bult in FancyArrowPatch. Is ther a possibility to use a selfmade design as arrow in python ? Is it possible to somehow add custom arrow styles to the FancyArrowPatch function ?
I have attached the image I want to reproduce with Python (taken from bsh.de/DE/DATEN/Stroemungen/stroemungen_node.html):
My best try was to produce this one:
Which is not quite satisfying yet. I would like to have the same arrows as seen in the first image. If you have suggestions how to make the image fancier I am open for that too.

How to automatically resize a plot on the important part, not showing the white parts?

I am currently trying to plot figures like this :
where i'm generating some random polytope located inside [-1,1]x[-1,1], then applying some optimization algorithms, and then plotting everything.
The problem is that because the polytopes are randomly generated, they can be very small or not centered, and it would be therefore convenient if i could remove the blank part on the sides.
I know it's possible to do it when saving a plot with something like plt.savefig('image.png', bbox_inches='tight'), but i would like to display it directly without white spaces (it's in a jupyter notebook so it would be more convenient).
I'm using a meshgrid to plot the data, and i have a 'None' at every blank pixel. I guess it could be possible to find some algorithm which finds the smallest square enclosing my polytope but i don't really want to go this way.
Do you have any ideas on how to do it using matplotlib ?

Displaying a grid of letters with coordinates on axes

I'm making a simple word game simulation in Python and need a way to visualise a grid of coordinates. The input would be a simple 2D array with either '' or a character in each spot.
I need each spot in the grid to either be blank or have one letter. The x and y axes need to have arbitrary start points, such as -20. It seems like Matplotlib might do what I want, but having looked around on a bunch of Stackoverflow questions and Matplotlib help pages, I can't find what I need.
The question here partly has what I need:
Show the values in the grid using matplotlib
Except I want no colour, the values are single characters, and the axis labels need to allow arbitrary start points.
Does anyone know whether Matplotlib is the right library to do this sort of thing, or if I should try something else? Performance matters but it's not the most important thing. I don't need any interactivity with the display window, it's purely read only.

Matplotlib export text as line elements in Python

I have to build some rudimentary CAD Tool in Python based on matplotlib for handling the display of the content.
After all the parts have been put together, the whole layout shall be exported as line elements (basically just tuples of the start / end coordinates of the lines, e.g. [x1,y1,x2,y2]) and just points.
So far I have all the basic gemoetric stuff implemented, but I cannot figure out how to implement text properly. To be able to use different fonts etc. I want to use the text capabilities of matplotlib, but I can't find a way to export the text properly from matplotlib.
Is there a way to get a vectorized output right away? Or at least an array of the plotted text?
After some days of struggling, I found a way to get the outline of the text: https://github.com/rougier/freetype-py , more precisely the example https://github.com/rougier/freetype-py/blob/master/examples/glyph-vector.py
If you just want to get the outline as an vector array, you can delete everything after line 78 and do this:
path = Path(VERTS, CODES)
outline = path.to_polygons()
This will give you an array of polygons, and each polygon is again an array of points (x,y) of the polygon.
Though it was some trouble to get freetype running on windows and I still have not figured out how to make it portable, I think I will stick with this solution, because it is fast, reliable and allows one to use all the nice system fonts.

Drawing a polygon in pygame [duplicate]

This question already has an answer here:
Drawing polygons in pygame using list
(1 answer)
Closed last month.
i am jaison i like to build an application for land survey process. for that i need to plot points in a canvas for a given gsi file. for example
the points be
a. .b
c. .d .e
these are the 5 points and i need to develop a tool to connect these points by line. while closing a boundry by like connecting points acdba. give it a parcel_id and other details like land owner, tax payment etc. save these details for feature query.
in real time the points will be more than 100000. and i need the canvas should have pan and zoom property.
friends i like to do this project in python using pygame. is it possible to do.
i am a newbie to python.
please need help.
Pygame is absolutely a good tool for this.
Look into using a pygame.surface object, and the pygame.draw module.
http://www.pygame.org/docs/ref/
If you need anything more complicated than dots, pygame.sprite is a relatively well developed module as well.
http://www.pygame.org/docs/ref/draw.html#pygame.draw.polygon
This is the function for drawing polygons in pygame. You can draw straight to screen or to a separate surface. I am not sure how fast it is with lots of points, you might want to split up what your drawing into smaller segments and just display what you need.
If you do need to show the whole polygon I would look into some way of compressing the amount of points to only get the general shape

Categories

Resources