Python: グラフのX-axis Tick Label Textをきちんと表示, matplotlib

Last Updated on

I.X-axis tick labelの文字が見えない

 

# import libraries 
import pandas as pd
from matplotlib import pyplot as plt
from covid19dh import covid19
# load the data
x = covid19(verbose=False)
# infected by population
confirmed_latest = x.query('date == "2020-07-21"')[['administrative_area_level_1', 'confirmed','population']]
confirmed_latest['confirmed_pop'] = (confirmed_latest['confirmed'] / confirmed_latest['population'])*10000
confirmed_latest.sort_values(by='confirmed', ascending=False).head(20)

confirmed_desc.plot(x = 'administrative_area_level_1',
                    y = 'confirmed',
                    kind="bar",
                    title = 'Confirmed 20200721',
                    logy=False)

 

 

II.文字を表示

 

次をように末尾に一行を加え、グラフを作成します。

 

confirmed_latest = x.query('date == "2020-07-21"')[['administrative_area_level_1', 'confirmed','population']]
confirmed_latest['confirmed_pop'] = (confirmed_latest['confirmed'] / confirmed_latest['population'])*10000
confirmed_latest.sort_values(by='confirmed', ascending=False).head(20)

confirmed_desc.plot(x = 'administrative_area_level_1',
                    y = 'confirmed',
                    kind="bar",
                    title = 'Confirmed 20200721',
                    logy=False)
plt.tight_layout()

 

 

Tight Layoutについては次に解説があります。

 

Tight Layout guide

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.