Full Download Hands-on Matplotlib: Learn Plotting and Visualizations with Python 3 Ashwin Pajankar PDF DOCX
Full Download Hands-on Matplotlib: Learn Plotting and Visualizations with Python 3 Ashwin Pajankar PDF DOCX
com
https://ebookmeta.com/product/hands-on-matplotlib-learn-
plotting-and-visualizations-with-python-3-ashwin-pajankar/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/raspberry-pi-image-processing-
programming-with-numpy-scipy-matplotlib-and-opencv-2nd-edition-ashwin-
pajankar-2/
ebookmeta.com
https://ebookmeta.com/product/raspberry-pi-image-processing-
programming-with-numpy-scipy-matplotlib-and-opencv-2nd-edition-ashwin-
pajankar/
ebookmeta.com
https://ebookmeta.com/product/digital-teaching-for-linguistics-1st-
edition-rebecca-gregory/
ebookmeta.com
The Industrial Organization of Banking Bank Behavior
Market Structure and Regulation 3rd 3rd Edition David
Vanhoose
https://ebookmeta.com/product/the-industrial-organization-of-banking-
bank-behavior-market-structure-and-regulation-3rd-3rd-edition-david-
vanhoose/
ebookmeta.com
https://ebookmeta.com/product/innovations-and-elaborations-in-
internal-family-systems-therapy-1st-edition-martha-sweezy/
ebookmeta.com
https://ebookmeta.com/product/managing-change-creativity-and-
innovation-3rd-edition-patrick-dawson-constantine-andriopoulos/
ebookmeta.com
Thousand Autumns Qian Qiu Vol 3 Meng Xi Shi
https://ebookmeta.com/product/thousand-autumns-qian-qiu-vol-3-meng-xi-
shi/
ebookmeta.com
Hands-on
Matplotlib
Learn Plotting and Visualizations
with Python 3
—
Ashwin Pajankar
Hands-on Matplotlib
Learn Plotting and Visualizations
with Python 3
Ashwin Pajankar
Hands-on Matplotlib
Ashwin Pajankar
Nashik, Maharashtra, India
Introduction�����������������������������������������������������������������������������������������������������������xvii
v
Table of Contents
vi
Table of Contents
Bar Graphs���������������������������������������������������������������������������������������������������������������������������������� 92
Scatter Plot��������������������������������������������������������������������������������������������������������������������������������� 95
Summary������������������������������������������������������������������������������������������������������������������������������������ 97
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
Chapter 18: Visualizing Real-Life Data with Matplotlib and Seaborn������������������� 269
COVID-19 Pandemic Data���������������������������������������������������������������������������������������������������������� 269
Fetching the Pandemic Data Programmatically������������������������������������������������������������������������ 271
Preparing the Data for Visualization������������������������������������������������������������������������������������������ 275
Creating Visualizations with Matplotlib and Seaborn���������������������������������������������������������������� 276
Creating Visualizations of Animal Disease Data������������������������������������������������������������������������ 287
Summary���������������������������������������������������������������������������������������������������������������������������������� 292
Index��������������������������������������������������������������������������������������������������������������������� 293
x
About the Author
Ashwin Pajankar earned a Master of Technology in computer science engineering from
IIIT Hyderabad and has more than 25 years of experience in the area of programming.
He started his journey in programming and electronics at the tender age of 7 with the
BASIC programming language and is now proficient in Assembly programming, C, C++,
Java, shell scripting, and Python. His other technical expertise includes single-board
computers such as the Raspberry Pi and Banana Pro, microcontroller boards such as the
Arduino, and embedded boards such as the BBC Micro Bit.
He is currently a freelance online instructor teaching programming to more
than 70,000 professionals. He also regularly conducts live programming bootcamps
for software professionals. His growing YouTube channel has an audience of more
than 10,000 subscribers. He has published more than 15 books on programming and
electronics.
In addition to his technology work, he volunteers for many social causes. He has
won several awards at his university and past workplaces for his community service.
He has also participated in many industry–institute linkage programs, connecting his
past employers with his alma maters. During the COVID-19 pandemic (which was
unfolding at the time of writing of this book), he participated in and led many initiatives
to distribute essential supplies and medicine to needy people in his local community.
xi
About the Technical Reviewer
Joos Korstanje is a data scientist with more five years of industry experience in
developing machine learning tools, especially forecasting models. He currently works
at Disneyland Paris where he develops machine learning for a variety of tools. He is the
author of the book Advanced Forecasting with Python.
xiii
Acknowledgments
I would like to thank Celestin and Aditee for giving me an opportunity to share my
knowledge and experience with readers. I thank James Markham for helping me to
shape this book according to Apress standards. I am in debt to the technical reviewer for
helping me to improve this book. I also thank Prof. Govindrajulu Sir’s family, Srinivas
(son) and Amy (daughter in law), for allowing me to dedicate this book to his memory
and for sharing his biographical information and photograph for publication. I would
also like to thank all the people at Apress who were instrumental in bringing this project
to reality.
xv
Introduction
I have been working in the domain of data science for more than a decade now, and I
was introduced to Python more than 15 years ago. When I first worked with libraries
such as NumPy, Matplotlib, and Pandas, I found it a bit tedious to comb through all
the available literature in the form of printed books, video tutorials, and online articles,
as most of them lacked comprehensive steps for beginners. It was then that I resolved
to write a book, and I am glad that I could bring my resolution to life with the help of
Apress.
This book is the result of thousands of hours (in addition to the ones spent writing
the actual book) going through technical documentation, watching training videos,
writing code with the help of different tools, debugging faulty code snippets, posting
questions and participating in discussions on various technical forums, and referring
to various code repositories for pointers. I have written the book in such a way that
beginners will find it easy to understand the topics. The book has hundreds of code
examples and images of code output so that you can fully understand each concept
introduced. All the code examples are explained in detail.
The book begins with a general discussion of Python and a small guide explaining
how to install it on various computing platforms such as the Windows OS and Linux
computers (like the Raspberry Pi). We then move on to discussing the scientific
ecosystem. Then we focus on NumPy, which is the fundamental library for numerical
computing. We specifically focus on the multidimensional, array-like data structure
of NumPy, called the Ndarray. We then explore data visualization libraries, such as
Matplotlib and Plotly, to learn how to plot Ndarrays.
Most of the chapters explore the data visualization library Matplotlib. You will learn a
lot of data visualization tips and techniques in these chapters.
Then we dive into Pandas so you can learn about its important data structures, called
the series and dataframe. Midway through the book, you will also learn how to read data
from various data sources using Python, NumPy, Matplotlib, and Pandas. You will also
learn how to visualize Pandas data with popular visualization libraries such as Matplotlib
and Seaborn, as well as how to work with time-indexed data.
xvii
Introduction
xviii
Another Random Scribd Document
with Unrelated Content
The Project Gutenberg eBook of In Korea with
Marquis Ito
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Language: English
Part I
A NARRATIVE OF PERSONAL EXPERIENCES
Part II
A CRITICAL AND HISTORICAL INQUIRY
BY
GEORGE TRUMBULL LADD, LL.D.
Copyright, 1908, by
CHARLES SCRIBNER’S SONS
Published February, 1908
TO THE
DEAR COMPANION
OF ITS EXPERIENCES AND THE
READY SCRIBE OF MUCH OF ITS MANUSCRIPT
THIS BOOK IS GRATEFULLY
AND AFFECTIONATELY
DEDICATED
PREFACE
The contents and purposes of this volume may be conveniently
classified under three heads; for here are statements of fact,
expressions of opinion, and certain ventures into the realm of
conjecture. The statements of fact are, almost without exception,
made on grounds of personal observation, or on the authority of the
most competent and trustworthy first-hand witnesses. For the earlier
periods of the history of the relations, friendly or hostile, between
Japan and Korea, these authorities are indeed no longer living, and
they cannot be subjected to cross-questioning. But the choice
between the truth they told and the mistakes and falsehoods of a
contradictory character is in most cases not difficult to make. For
events of the present generation the reader will find the statements
of the witnesses quoted, and of the documents cited, to be in general
unimpeachable. I believe, then, that what is claimed to be truth of
fact in this book is as nearly exact and worthy of implicit confidence
as it is ordinarily given to human beings to be in matters pertaining to
the history of human affairs.
In expressing my own opinions as to the truth or untruth of certain
contentions, and as to the merit or demerit of certain transactions, I
have uniformly tried to base these opinions upon the fullest
obtainable knowledge of the facts. In some cases the judgments at
which I have been compelled to arrive contradict those which have
been and still are widely current; in some cases they can scarcely
fail to be interpreted as an impeachment of other writers who have
had either a narrator’s interest only in the same events or even a
more substantial concernment. I have no wish to deny the apologetic
character of this book. But at every point the charge of being
swerved from the truth by prejudice may be met with these replies:
First, very unusual opportunities were afforded the author for
ascertaining the truth; and, second, in almost every case where the
evidence brought forward seems insufficient there is much more of
the same sort of evidence already in his possession, and still more to
be had for the asking. But in these days one must limit the size of
such undertakings. Few readers wish to wade through a long stretch
of shoals in order to reach the firm ground of historical verity.
As to the ventures at conjecture which are sparingly put forth, let
them be rated at their seeming worth, after the facts have been
carefully studied and the opinions weighed, which have called out
these ventures. They are confessedly only entitled to a claim for a
certain degree, higher or lower, of probability. The status of all things
in the Far East—and for the matter of that, all over the civilized world
—is just now so unstable and loaded with uncertainties that no
human insight can penetrate to the centre of the forces at work, and
no human foresight can look far into the future.
The division of the book into two parts may seem at first sight to
injure its unity. Such a division has for its result, as a matter of
course, a somewhat abrupt change in the character of the material
employed and in the style of its handling. The First Part is a narrative
of personal observations and experiences. It gives the results,
however, of a serious study of a complicated situation; and it
pronounces more or less confident judgments upon a number of
subordinate questions involved in the general problem of
establishing satisfactory relations between two nations which are
inseparably bound together—physically, socially, politically—whether
for the weal or for the woe of both. In the Second Part the attempt is
made to submit these judgments to the tests of history. But what is
history? Of no other civilized country than Korea is the truth of the
cynical saying more obvious that much of what has been written as
history is lies, and that most of real history is unwritten. All of which
has tended to make the writer duly appreciate the unspeakable
advantage of having access to authentic information which, for
diplomatic and other sufficient reasons, has not hitherto been made
public.
The underlying literary and logical unity which binds together the
two seemingly diverse Parts of the one book is made clear by stating
in general terms the problem upon which it aims to throw light. This
problem concerns the relations to be established between Japan and
Korea—a question which has for centuries been proposed in various
imperative and even affective ways to both these nations. It is also a
question which has several times disturbed greatly the entire Orient,
and the recent phases of which have come near to upsetting the
expectations and more deliberate plans of the entire civilized world.
To lay the foundations, under greatly and suddenly changed
conditions, of a satisfactory and permanent peace, one of the
greatest statesmen of the Orient is giving—with all his mind and
heart—the later years of his eventful life. I hope that this book may
make its readers know somewhat better what the problem has been
and is; and what Prince Ito, as Japanese Resident-General in Korea,
is trying to accomplish for its solution.
It remains for the Preface only to acknowledge the author’s
obligations. These are so special to one person—namely, Mr. D. W.
Stevens, who has been for some time official “Adviser to the Korean
Council of State and Counsellor to the Resident-General”—that
without his generous and painstaking assistance in varied ways the
Second Part of the book could never have appeared in its present
form. It is hoped that this general acknowledgment will serve to
cover many cases where Mr. Stevens’ name is not especially
mentioned in connection with the text. Grateful acknowledgment is
also made to Mr. Furuya, the private secretary of the Resident-
General, for his painstaking translation from the original Japanese or
Chinese official documents; to Mr. M. Zumoto, editor of the Seoul
Press, for varied information on many subjects; and to Dr. George
Heber Jones for facts and suggestions imparted in conversation and
embodied in writings of his. My obligations to the Resident-General
himself, for the perfectly untrammelled and unprejudiced opportunity,
with its complete freedom to ask all manner of questions, which his
invitation afforded, are, I trust, sufficiently emphasized in the title of
the book. Other debts to writers upon any part of the field are
acknowledged in their proper connections.
George Trumbull Ladd.
Hayama, Japan, September, 1907.
CONTENTS
CONTENTS OF PART I
CHAPTER PAGE
I. The Invitation 1
II. First Glimpses of Korea 15
III. Life in Seoul 37
IV. Life in Seoul (Continued) 65
V. The Visit To Pyeng-yang 90
VI. Chemulpo and Other Places 112
VII. The Departure 139
VIII. Personal Reminiscences and Impressions 148
CONTENTS OF PART II
IX. The Problem: Historical 179
X. The Problem: Historical (Continued) 222
XI. The Compact 252
XII. Rulers and People 280
XIII. Resources and Finance 300
XIV. Education and the Public Justice 326
XV. Foreigners and Foreign Relations 352
XVI. Wrongs: Real and Fancied 367
XVII. Missions and Missionaries 388
XVIII. July, 1907, and After 414
XIX. The Solution of the Problem 444
ILLUSTRATIONS
Portrait of Marquis Ito Frontispiece
TO FACE PAGE
Bird’s-Eye View of the Capital City 22
Going to the Lecture at Independence Hall 52
Water-gate at Pyeng-yang 100
West Gate or “Gate of Generous
Righteousness” 132
Peony Point at Pyeng-yang 184
The Tong-Kwan Tai-Kwol Palace 206
The Ex-Emperor and Present Emperor 284
The Hall of Congratulations 306
Street Scene in Seoul 330
The Stone-Turtle Monument 384
Funeral Procession in Seoul 408
PART I
A NARRATIVE OF PERSONAL EXPERIENCES
CHAPTER I
THE INVITATION
It was in early August of 1906 that I left New Haven for a third visit
to Japan. Travelling by the way of the Great Lakes through Duluth
and St. Paul, after a stay of two weeks in Seattle, we took the
Japanese ship Aki Maru for Yokohama, where we arrived just before
the port was closed for the night of September 20. Since this ship
was making its first trip after being released from transport service in
conveying the Japanese troops home from Manchuria, and was
manned by officers who had personal experiences of the war to
narrate, the voyage was one of uncommon interest. Captain Yagi
had been in command of the transport ship Kinshu Maru when it was
sunk by the Russians, off the northeastern coast of Korea. He had
then been carried to Vladivostok, and subsequently to Russia, where
he remained in prison until the end of the war. Among the various
narratives to which I listened with interest were the two following;
they are repeated here because they illustrate the code of honor
whose spirit so generally pervaded the army and navy of Japan
during their contest with their formidable enemy. It is in reliance on
the triumph of this code that those who know the nation best are
hopeful of its ability to overcome the difficulties which are being
encountered in the effort to establish a condition favorable to safety,
peace, and prosperity by a Japanese Protectorate over Korea.
At Vladivostok the American Consul pressed upon Captain Yagi a
sum of money sufficient to provide a more suitable supply of food
during his journey by rail to Russia. This kindly offer was respectfully
declined on the sentimental ground that, as an officer of Japan, he
could not honorably receive from a stranger a loan which it was
altogether likely he would never be able to repay. But when still
further urged, although he continued to decline the money, he
begged only the Consul’s card, “lest he might himself forget the
name or die,” and so his Government would be unable to
acknowledge the kindness shown to one of its officers. The card was
given, sent to Tokyo, and—as the Captain supposed—the Consul
was “thanked officially.” The first officer, an Englishman, who had
been in the service of Japan on the Aki Maru, while it was used for
transporting troops to Manchuria and prisoners on its return, told this
equally significant story. His ship had brought to Japan as prisoner
the Russian officer second in command at the battle of Nan-san.
Having been wounded in the foot, the Russian was, after his capture,
carried for a long distance by Japanese soldiers, to whom, when
they reached the hospital tent, he offered a $20 gold-piece. But they
all refused to receive money from a wounded foe. “If it had been
Russian soldiers,” said this officer of his own countrymen, “they
would not only have taken this money but would have gone through
my pockets besides.”
Before leaving home only two official invitations had been
received, namely, to lecture on Education before the teachers in the
Tokyo branch of the Imperial Educational Society; and to give a
course in the Imperial University of Kyoto, on a topic which it was
afterward decided should be the “Philosophy of Religion.” This
university was to open in the following autumn a Department of
Philosophy (such a forward movement having been delayed by the
war with Russia). Almost immediately on our arrival, a multitude of
requests for courses of lectures and public addresses came to the
committee in charge of the arrangements, with the result that the six
months from October 1, 1906, to April 1, 1907, were crowded full of
interesting and enjoyable work. In the intervals of work, however,
there was opportunity left for much valuable social intercourse and
for meeting with men like Togo, Oyama, Noghi, and others in military
and business, as well as educational circles, whose names and
deeds are well known all over the civilized world. But it is not the
narrative of these six months which is before us at the present time,
although doubtless they had a somewhat important influence in
securing the opportunity and providing the preparation for the
subsequent visit to Korea.
The thought of seeing something of the “Hermit Kingdom” (a title,
by the way, which is no longer appropriate) had been in our minds
before leaving America, only as a somewhat remote possibility. Not
long after our arrival in Japan the hint was several times given by an
intimate friend, who is also in the confidence of Marquis Ito, that the
latter intended, on his return in mid-winter from Seoul, to invite us to
be his guests in his Korean residence. It was not, however, until the
afternoon of December 5 that the invitation was first received. This
was at the garden-party given by Marquis Nabeshima on his sixty-
first birthday. It should be explained that every Japanese is born
under one of the twelve signs—corresponding to our signs of the
Zodiac. When five of these periods have been completed the total of
sixty years corresponds with the end of six periods of ten years each
—a reckoning which is, I believe, of Chinese origin. The fortunate
man, therefore, may be said to begin life over again; and presents
such as are ordinarily appropriate only to childhood are entirely in
order on such a festal occasion. While walking in the beautiful
garden, which is of Japanese style but much modified by Italian
ideals, the private secretary of Marquis Ito, Mr. Furuya, came to us
and announced that his chief, who had recently returned from Seoul
to Japan, was near and wished to see me. After an exchange of
friendly greetings almost immediately the Marquis said: “I am
expecting to see you in my own land, which is now Korea”; and when
I jestingly asked, “But is it safe to be in Korea?” (implying some fear
of a Russian invasion under his protectorate) he shook his fist
playfully in the air and answered: “But I will protect you.” To this he
added, pointing to his sword: “You see, I am half-military now.” The
significance of the last remark will be the better understood when it is
remembered that from the days of his young manhood to the present
hour, Ito has always stood for the peaceful policy and the cultivation
of friendly relations between Japan and all the rest of the world. For
this reason he has never been the favorite of the military party; and
he is to-day opposed in his administration of Korean affairs by those
who would apply to them the mailed hand of punishment and
suppression rather than hold out the friendly but firm hand of
guidance and help.
Even after this interview the real purpose of the invitation to visit
Korea was not evident. A week later, however, it was disclosed by a
visit from Mr. Yamada of the Japan Times, who came from Marquis
Ito to present his request more fully and to arrange for a subsequent
extended conference upon the subject. I was then informed, in a
general way, how it was thought by the Resident-General I might be
of help to him and to Japan in solving the difficult problem of
furthering for the Koreans themselves the benefits which the existing
relations of the two countries made it desirable for both to secure.
Complaints of various sorts were constantly being made, not only
against individual Japanese, but also against the Japanese
administration, as unjust and oppressive to the Koreans, and as
selfish and exclusive toward other foreigners than its own
countrymen. Especially had such complaints of late been propagated
by American missionaries, either directly by letters and newspaper
articles, or more indirectly by tales told to travellers who, since they
were only passing a few days in Korea, had neither desire nor
opportunity to investigate their accuracy. In this way, exaggerations
and falsehoods were spread abroad as freely as one-sided or half-
truths. In the office of Resident-General the Marquis greatly desired
to be absolutely just and fair, and to prevent the mistakes, so harmful
both to Korea and to Japan, which followed the Japanese occupation
of Korea at the close of the Chino-Japan war. But it was difficult, and
in most cases impossible, for him even to find out what the
complaints were; they came to the public ear in America and
England before he was able to get any indication of their existence
even. And when his attention was called to them in this roundabout
fashion, further difficulties, almost insuperable, intervened between
him and the authors of these complaints; for in most cases it turned
out that the foreign plaintiffs had no first-hand information regarding
the truth of the Korean stories. They would not themselves take the
pains to investigate the complaints, much less would they go to the
trouble to bring the attention of the Resident-General to the matters
complained of in order that he might use his magisterial authority to
remedy them. In respect to these, and certain other difficulties,
Marquis Ito thought that I might assist his administration if I would
spend some time upon the ground as his guest.
The nature of this invitation put upon me the responsibility of
answering two questions which were by no means altogether easy of
solution; and on which it was, from their very nature, impossible to
get much trustworthy advice. The first of these concerned my own
fitness for so delicate and difficult but altogether unaccustomed
work. The second raised the doubt whether I could in this way be
more useful to Japan and to humanity than by carrying out the
original plan of spending the spring months lecturing in Kiushu. After
consulting with the few friends to whom I could properly mention the
subject, and reflecting that the judgment of His Imperial Majesty, with
whom Marquis Ito would doubtless confer, as well as of the
Resident-General himself, might fairly be considered conclusive, I
accepted the invitation; but it was with mingled feelings of pleasure
and of somewhat painful hesitation as to how I should be able to
succeed.
The illness of Marquis Ito which, though not serious, compelled
him to retire from the exciting life of the capital city to the seaside,
and then to the hills, prevented my meeting him before I left Tokyo
for Kyoto to fulfil my engagements in the latter city. But, by
correspondence with a friend, I was kept informed of the Marquis’
plans for his return to Korea, and thus could govern my
engagements so as to be in the vicinity of some point on his route
thither, at which the meeting with him might take place.
The expected conference followed immediately after our return
from one of the most delightful of the many gratifying experiences
which came to us during our year in Japan. We had taken a trip to
the village of Hiro Mura, where formerly lived Hamaguchi Goryo, the
benevolent patron of his village, whose act of self-sacrifice in burning
his rice straw in order to guide the bewildered villagers to a place of
safety when they were being overwhelmed by a tidal wave in the
darkness of midnight, has been made the theme of one of Lafcadio
Hearn’s interesting tales. Mr. Hearn, it appears, had never visited the
locality; and, indeed, we were assured that we were the first
foreigners who had ever been seen in the village streets. A former
pupil of mine is at the head of a flourishing school patronized by the
Hamaguchi family; and having accepted his invitation, in the name of
the entire region, to visit them and speak to the school and to the
teachers of the Prefecture, the cordial greeting, hospitable
entertainment, and the surpassingly beautiful scenery, afforded a
rich reward for the three or four days of time required. For, as to the
scenery, not the drive around the Bay of Naples or along the