When I made a treemap (area graph) with python, it was subtle, so when I used flourish, it felt pretty good.

In other words?

If it was matplotlib

treemap3.png

If it's flourish スクリーンショット 2019-12-07 19.49.53.png

Source of data

https://www.stat.go.jp/data/nihon/02.html

When making with python [^ 1]

If you don't have a library for treemaps, `` `squarify```

pip3 install squarify
# lib
import pandas as pd
import squarify #Treemap Ploting
import matplotlib
from matplotlib import style
import matplotlib.pyplot as plt
import seaborn as sns

# Activate Seaborn
sns.set()
%matplotlib inline

#Size and font settings
matplotlib.rcParams['figure.figsize'] = (16.0, 9.0)
plt.rcParams['font.family'] = 'Hiragino Sans'  
plt.rcParams['font.weight'] = 'bold'

#Use ggplot style
style.use('ggplot')

#dataframe creation
population = [7369,3788,14360,21356,19476,22431,43248]
label = ["China(5.58%)","Shikoku(2.87%)","Kyushu-Okinawa\n(10.88%)","Chubu(16.18%)","Hokkaido and Tohoku(14.75%)","Kansai(16.99%)","Kanto(32.76%)"]
percentage = [5.58,2.87,10.88,16.18,14.75,16.99,32.76]
df = pd.DataFrame({"Population":population,"Label":label,"Percentage":percentage})

fig, ax = plt.subplots()
# Colormap
cmap = matplotlib.cm.Blues
# Min and Max Values
mini = min(df["Population"])
maxi = max(df["Population"])
# colors setting
norm = matplotlib.colors.Normalize(vmin=mini, vmax=maxi)
colors = [cmap(norm(value)) for value in df["Population"]]
# Plotting
squarify.plot(sizes=df["Population"], label=df["Label"], alpha=0.8, color=colors, text_kwargs={'fontsize':24,'color':'grey'})
#Axis deletion
plt.axis('off')
#y-axis reverse
plt.gca().invert_yaxis()
#Title, position setting
plt.title("Japan's population ratio by region", fontsize=32,fontweight="bold")
ttl = ax.title
ttl.set_position([.5, 1.05])
#Background color
fig.set_facecolor('#eeffee')

When I do treemap3.png

It will be like this. It's kind of crap ...

So, let's try using the service flourish: https: //app.flourish.studio/ that can visualize nicely.

When using flourish

Please use a google account or something to register.

  1. Select new project スクリーンショット 2019-12-07 20.07.16.png

  2. Select treemap スクリーンショット 2019-12-07 20.08.02.png

You can create it with. The data used this time is as follows. スクリーンショット 2019-12-07 20.13.00.png

Nesting is set by region → prefecture. Of course, Size by specifies the estimated population for 2017. As you can see, you can use Japanese, and you can operate it in the same way as spreadsheet tools such as Excel.

I will repost the treemap using flourish. (The label disappears when you download it normally, so I'm taking a screenshot) スクリーンショット 2019-12-07 19.49.53.png

Recommended Posts

When I made a treemap (area graph) with python, it was subtle, so when I used flourish, it felt pretty good.
I made a segment tree with python, so I will introduce it
A story that I was addicted to when I made SFTP communication with python
I made a fortune with Python.
I made a daemon with Python
I made a Discord bot in Python that translates when it reacts
Every time I draw a graph with python, I check it, so I will summarize only the simplest usage
I made a Hex map with Python
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
I made a familiar function that can be used in statistics with Python
I was able to mock AWS-Batch with python, moto, so I will leave it
A note I was addicted to when running Python with Visual Studio Code
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
[Python] I made a Youtube Downloader with Tkinter.
I made a random number graph with Numpy
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
A Python beginner made a chat bot, so I tried to summarize how to make it.
[Memorandum] python + vscode + pipenv It's common, but it was a mess with warning, so a memorandum
When I used Plotly to draw an interactive graph, it was more than I expected.
I made a Twitter BOT with GAE (python) (with a reference)
I made a Christmas tree lighting game with Python
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
It was a painful memory when I was told TypeError: must be type, not class obj when trying to inherit with Python.
[Python] I made a function that decrypts AES encryption just by throwing it with pycrypto.
I'm always impatient when ordering a cafe, so I made a React app to solve it.
I made a server with Python socket and ssl and tried to access it from a browser
I made a function to crop the image of python openCV, so please use it.
There was a doppelganger, so I tried to distinguish it with artificial intelligence (laughs) (Part 1)
A story that stumbled when I made a chatbot with Transformer
When I made CaboCha usable with python3, I got stuck (Windows 10)
I made a simple typing game with tkinter in Python
I made a package to filter time series with python
I made a simple book application with python + Flask ~ Introduction ~
[I made it with Python] XML data batch output tool
I made a puzzle game (like) with Tkinter in Python
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
I came across an image filter with a clearly Japanese name called Kuwahara filter, and when I tried it, it was amazing, so I will introduce it.
GCP's Cloud Shell Editor was clogged up with the Python development environment, so I managed to rebuild it in a vacant lot.
I made blackjack with python!
I made a python text
I made blackjack with Python.
I made wordcloud with Python.
Life game with Python [I made it] (on the terminal & Tkinter)
I made a simple circuit with Python (AND, OR, NOR, etc.)
I made a library to easily read config files with Python
I made a package that can compare morphological analyzers with Python
A memorandum when I tried to get it automatically with selenium
I made a Nyanko tweet form with Python, Flask and Heroku
I made a lot of files for RDP connection with Python
[Python] I made an image viewer with a simple sorting function.
A note I was addicted to when creating a table with SQLAlchemy