avatarJainvidip

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2005

Abstract

="8ae6">台灣真的很愛考試。企業非常喜歡在面試前就先弄一大堆筆試,我試過應徵一份工作,先花了三個小時筆試(包括性格測驗、數學題、英文題、邏輯題等等),再花兩個小時聽介紹會,最後沒空額面試。我一開始不懂為什麼身邊的台灣人總會說要「考」哪家公司,經過親身感受後,終於明白雇主要求職者花很多時間心力去「考」進去公司工作,是真的要「考試」的「考」進去工作。我在香港求職從來都只是隨便丟個履歷,約面試,面試也只是隨便聊聊天,重點是看你的學歷、工作經歷、工作能力、個人應對能力反應OK就聘用了,如果是應徵正職員工,那進去直接就是正職員工,如果有試用期的話過了試用期沒什麼特別也會直接轉正。可是台灣呢,居然連試用期過後還要再「考試」才有機會轉正職員工。重點又來了,薪水才那麼一丁點。</p><p id="3938">休假制度</p><p id="49f4">在香港工作,大家都會覺得香港的勞工制度真的很壓榨,對勞工很不公平,工時長加班又沒補錢,通勤時間長很常塞車,真是打工仔地獄。那現在我可以大聲的說,沒有最地獄只有更地獄。台灣首年的基本年假只有三天。周休六、日在香港很普遍,在台灣南部想朝九晚五周休六、日?開玩笑!有很多工作都只有月休八天,而且還要排休,也不用提台灣的「晚班」文化,人力銀行一堆要求上晚班的工作。台灣勞資法規定工時、加班補錢或補休的規定,老老實實有多少個雇主真的有在遵守,有多少企業打著「責任制」的名號要求員工無償加班,上面這一堆如果要討論的話會沒完沒了,在此就先請各位讀者自己心神意會了。再補充一句,台灣沒有復活節和聖誕節假期喔。</p><p id="3392">香港人的優勢</p><p id="d6bc">在移民來台灣之前,自己一定會覺得香港人定必會有很大的優勢,因為香港大學入學率那麼低,又是半英語環境,光是學歷和英語能力就O打台灣絕大部份人了。不止自己有這個想法,連身邊的家人、台灣的朋友也會這樣想,對不對?這樣想你就大錯特錯了!我可以很肯定的告訴你,除非你在香港就是特定專業人士,而且專業到是台灣很搶手的人才,不然哪怕你在香港哪一所大學畢業、在香港工作經驗有多豐富,你連一個台灣大學畢業新鮮人也不如。</p><p id="655a">第一,你剛來台灣一張檢定都沒有;第二,你不會台語是要怎樣服務南部顧客及與上司同事溝通;第三,你沒駕照工作上要使喚你很不方便;第四,外藉人士要辦勞保健保還有一大堆針對外藉人士專有的稅務、法規要注意,太麻煩了吧;第五,你在哪一所大學畢業沒什麼特別呀在台灣大學畢業是基本;第六,英語能力強喔,那多益有金色證書嗎?會議可以即時口譯嗎?;第七,你以前在香港工作經驗很豐富,職位高薪水好,那怎麼可能來台灣應徵這麼低工資的工作;…光是以上種種考慮,我是雇主的話還不如請一個台灣本地大學畢業生比較實在。</p><p id="bd09">台灣找工作真的那麼難嗎</p><p id="221b">說實在,在南部如果不怕體力活,又喜歡面對客戶會一點點台語的話,有非常多的門市前線及業務開發類工作很缺人。可是如果你是像我一樣有點挑工作,希望內勤的、對電腦的文職,又不想排班輪休,想要有固定的工作時間、有一定的休假,安安份份當一個小OL的話,那在南部找工作就需要很大的耐心慢慢找了。像我找了一個半月,說長不長,最後一定能找到工作。台灣這個地方無法保你發財,可是保你不死。</p><p id="ac48">要融入台灣,求職是一個必經的過程,在當中會切身感受到台灣人找不到工作的艱難和找到工作的可貴。經歷過困難的求職路,對得來不易的工作才會百般珍惜。各位新移民/準備移民/考慮移民的香港朋友,加油。</p> <figure id="d49e"> <div> <div> <img class="ratio" src="http://placehold.it/16x9"> <iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fbutton.like.co%2Fin%2Fembed%2Fivypoon125%2Fbutton%2F&amp;display_name=LikeCoin&amp;url=https%3A%2F%2Fbutton.like.co%2Fivypoon125&amp;image=https%3A%2F%2Fstorage.googleapis.com%2Flikecoin-foundation.appspot.com%2Flikecoin_store_user_ivypoon125_main%3FGoogleAc

Options

cessId%3Dfirebase-adminsdk-eyzut%2540likecoin-foundation.iam.gserviceaccount.com%26Expires%3D2430432000%26Signature%3DbIJSXRoDceG0E2d%252BE8fyg1M3GYmm%252Fw9r0q8gdm79CCJiIbYynSjcdMxkiuEt6R7I60%252FcB8ZiphagXr4%252BHwZKsuebQGVsH7WM1I60Rl%252B7f2HKjn2sCU7FPZSjGsSHz%252F3stMEwYgFeR9HjOK5W0ZtQ5L4XwxeVT36KOXuDSTs7Nz0iAgQqUrHpzlg3f413qXd4PTvBwrqb3nI8jRbZ9aYnJX9fSDzcSoPBY9e%252F0tg9izV0hKhIlJb0Fg00s%252FfXoQyKZzhzhNSh1rfm0B%252BMFeUKXgtcTh3WmKq8sVKKJ0pgChrcXbBJzGKYnO14p%252Bx28xqTaqePn%252F3tz9mLLjPxpk79rw%253D%253D&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=like" allowfullscreen="" frameborder="0" height="212" width="485"> </div> </div> </figure></iframe></div></div></figure><div id="715d" class="link-block"> <a href="https://medium.com/@pp125/%E4%BE%9D%E8%A6%AA%E7%A7%BB%E6%B0%91%E5%8F%B0%E7%81%A3-%E4%B8%80-%E8%89%AF%E6%B0%91%E8%AD%89%E7%94%B3%E8%AB%8B-d73fb8b15646"> <div> <div> <h2>依親移民台灣(一)- 良民證申請</h2> <div><h3>申請台灣居留需要各種證件和文件,各種文件有不一樣的處理時間、遞送時間、有效期,需要注意並且做好時間配合。</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*pv_CSHw_5VstN6hwzX3-Sw.jpeg)"></div> </div> </div> </a> </div><div id="2ee8" class="link-block"> <a href="https://medium.com/@pp125/%E4%BE%9D%E8%A6%AA%E7%A7%BB%E6%B0%91%E5%8F%B0%E7%81%A3-%E4%BA%8C-%E9%AB%94%E6%AA%A2-82ff6de6a84e"> <div> <div> <h2>依親移民台灣(二)- 體檢</h2> <div><h3>台灣的身體檢查 (Body Check) 簡稱「體檢」。</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/)"></div> </div> </div> </a> </div></article></body>

Plot like a Pro: Matplotlib 101

Welcome to a full comprehensive guide that will guide you from no knowledge about matplotlib to a prodigy which will allow you to plot like a pro.

Now before we start learning matplotlib we should know what it actually is.

What is Matplotlib?

Matplotlib is one of the most widely used data visualization libraries in Python. It’s powerful, flexible, and easy to use, making it an essential tool for anyone working with data. In this blog, we will take a journey from the basics to advanced functionalities of Matplotlib. Whether you are a beginner or looking to polish your skills, this guide has something for everyone.

Before using matplotlib it is important to have it installed in your system. You can do it by typing the following command in your command prompt.

pip install matplotlib

To get started, you need to import the library. The standard way to import Matplotlib is:

import matplotlib.pyplot as plt
import numpy as np

Here plt is the alias that we have given so that it is easy to call the library when we need to use it.

We are also importing numpy here which is another python library that is used to work with arrays. You can read more about it here.

Matplotlib allows us to plot various types of plots. We will go through them one by one.

Line plot

  • Description: Creates a line plot.
  • Example: plt.plot(x, y) plots the values of y against x as a continuous line.
import matplotlib.pyplot as plt # Importing matplotlib
import numpy as np # Importing numpy 

# Creating sample data
x = np.linspace(0, 10, 100) # Generating 100 evenly distributed values between 0 and 10
y = np.sin(x) # Calculating the sin of values of x

plt.plot(x, y) # Plotting y against x
plt.title("Simple Line Plot") # Gives the plot title
plt.xlabel("X-axis") # Labels the x axis of the plot
plt.ylabel("Y-axis") # Labels the y axis of the plot
plt.show() # Displays the final plot

Output

Scatter Plot

  • Description: Creates a scatter plot.
  • Example: plt.scatter(x, y) plots the values of y against x as individual points.
import matplotlib.pyplot as plt
import numpy as np

# Generating random data
x = np.random.rand(50)
y = np.random.rand(50)

plt.scatter(x, y) # Plotting scatter plot as individual points
plt.title("Scatter Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

Output

Bar Plot

  • Description: Creates a bar plot.
  • Example: plt.bar(categories, values) plots bars for each category with the corresponding values.
import matplotlib.pyplot as plt
import numpy as np

# Generating the data
categories = ['A', 'B', 'C', 'D'] # Specifying the categories
values = [3, 7, 5, 4] # Specifying the values of each category

plt.bar(categories, values) # Plotting bar plot for each category with corresponding values
plt.title("Bar Plot")
plt.xlabel("Categories")
plt.ylabel("Values")
plt.show()

Output

Basic Plot Customization

You may feel like these plots look very basic and dull, well you are right but matplotlib allows various customization options as well to make our graphs come to life.

Legend()

Places a legend on the axis

x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

plt.plot(x, y1, label='sin(x)') # label specifies what we want the name on the legend
plt.plot(x, y2, label='cos(x)')
plt.title("Sine and Cosine Waves")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.legend() # Places a legend on the axis
plt.show()

Output

Line Styles and Colors

  • color: Sets the line color
  • linestyle: Sets the line style
  • linewidth: Sets the line width
x = np.linspace(0, 10, 100)
y = np.sin(x)

# color sets the color
# The style and width of the line can also be changed
plt.plot(x, y, color='blue', linestyle='--', linewidth=2)
plt.title("Styled Line Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

Output

Markers

We can also add markers to our plots

  • marker: Sets the marker style
  • markersize: Sets the marker size
  • markerfacecolor: Sets the marker face color
  • markeredgecolor: Sets the marker edge color
x = np.linspace(0, 10, 10)
y = np.sin(x)

plt.plot(x, y, marker='o', markersize=10, markerfacecolor='red', markeredgecolor='black')
plt.title("Line Plot with Markers")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

Output

Grid

  • plt.grid(): Adds grid lines to the plot
x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.plot(x, y)
plt.title("Plot with Grid Lines")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.grid(True)
plt.show()

Output

Subplots

  • plt.subplots(): Creates multiple plots in a single figure
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# Create a figure and an array of subplots with 2 rows and 1 column
fig, axs = plt.subplots(2,1)
axs[0].plot(x, y1, 'r')
axs[0].set_title('Sin(x)')
axs[1].plot(x, y2, 'b')
axs[1].set_title('Cos(x)')

# Adjust the layout to prevent overlap
plt.tight_layout()
plt.show()

Output

Annotations

plt.annotate(): Adds annotations to the plot

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.plot(x, y)
plt.title("Plot with Annotation")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.annotate('Max', xy=(np.pi/2, 1), xytext=(np.pi/2 + 1, 1.5),
             arrowprops=dict(facecolor='black', shrink=0.05))
plt.show()

Output

Logarithmic Scale

Using matplotlib we can set our scale to logarithmic scale

  • plt.yscale(): Sets the y-axis to a logarithmic scale
  • plt.xscale(): Sets the x-axis to a logarithmic scale
x = np.linspace(1, 10, 100)
y = np.exp(x)

plt.plot(x, y)
plt.title("Logarithmic Scale")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.yscale('log')
plt.show()

Output

Figure Size and Resolution

We can specify figure size and resolution of our plots

plt.figure(figsize=(width, height), dpi=dpi): Customizes the size and resolution of the plot

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.figure(figsize=(8, 4), dpi=100) # This helps us specify the figure size and resolution
plt.plot(x, y)
plt.title("Custom Figure Size and DPI")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

Output

Color Maps

We can also add some colour to our graphs

cmap: Applies a colormap to the plot

x = np.random.rand(100)
y = np.random.rand(100)
colors = np.random.rand(100)

plt.scatter(x, y, c=colors, cmap='viridis')
plt.colorbar()  # Shows color scale
plt.title("Scatter Plot with Colormap")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

Output

Customized Plot

Now I will display a plot using all the customizations that we used. It might look like a huge code at first but when you focus and try to understand you will see that we have covered all the topics and you can generate a similar graph yourself.

# All customizations
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

plt.figure(figsize=(10, 6), dpi=100) # Setting our fig size and resolution

# Setting plot line color, linestyle, linewidth, adding a marker and a label
plt.plot(x, y1, color='blue', linestyle='--', linewidth=2, marker='o', markersize=6, markerfacecolor='red', label='sin(x)')
plt.plot(x, y2, color='green', linestyle='-', linewidth=2, marker='s', markersize=6, markerfacecolor='yellow', label='cos(x)')


plt.title("Customized Plot") # Giving title to plot
plt.xlabel("X-axis") # Labelling x axis
plt.ylabel("Y-axis") # Labelling y axis
plt.legend() # Displaying the legend
plt.grid(True) # Displaying the grid

# Setting up some annotations
plt.annotate('Max sin', xy=(np.pi/2, 1), xytext=(np.pi/2 + 1, 1.5), arrowprops=dict(facecolor='black', shrink=0.05))
plt.annotate('Min cos', xy=(3*np.pi/2, -1), xytext=(3*np.pi/2 - 1, -1.5), arrowprops=dict(facecolor='black', shrink=0.05))

plt.show()

Output

Now that you know all the different types of customizations you can explore each one and tinker with the graphs yourself and have some fun.

Now let’s continue on our journey to understand more different types of graphs that we can plot using matplotlib

Pie Chart

Pie charts are a circular statistical graphic, which is divided into slices to illustrate numerical proportions

# Pie Charts
import matplotlib.pyplot as plt

# Data to plot
labels = 'A', 'B', 'C', 'D' # Labels for each slice of the pie chart
sizes = [15, 30, 45, 10] # The data or the size of the pie charts
colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue'] # Colors for the different slices of pie chart
explode = (0.1, 0, 0, 0)  # Exploding the 1st slice 

# Create a pie chart
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=140)
# Specifying the sizes, explode, labels and colors
# %1.1f%%' displays the percentage value with one decimal place and a percent sign
# Shadow = True turns on the shadow
# This argument rotates the pie chart so that the first slice ('A') starts at 140 degrees counterclockwise from the positive x-axis
plt.title("Pie Chart")
plt.show()

Output

Histogram

We can use plt.hist() function to plot a histogram

import matplotlib.pyplot as plt
import numpy as np

# Creating a NumPy array named data containing 1000 random numbers
data = np.random.randn(1000)

# Data is the data we need to plot
# Bins is the number of bars we want or the number of divisions we want in our data
plt.hist(data, bins=30)
plt.title("Histogram")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()

Output

Heatmap

We can use plt.imshow() to plot a heatmap. Heatmap is an extremely useful plot that is widely used in EDA which I will cover in a future blog. Right now just focus on learning how a heatmap can be plotted.

import matplotlib.pyplot as plt
import numpy as np

data = np.random.rand(10, 10)

# cmap specifies the colormap
# interpolation method used to determine the color for pixels that don't fall exactly on a data point in the array
plt.imshow(data, cmap='hot', interpolation='nearest')
plt.colorbar()
plt.title("Heatmap")
plt.show()

Output

Box Plots

Box plots are a great way to visualize the distribution of data and identify outliers. They display the median, quartiles, and potential outliers in your dataset.

We can use plt.boxplot() to plot a boxplot.

import matplotlib.pyplot as plt
import numpy as np

# Generate some random data
np.random.seed(10) # This line sets a seed for the random number generator in NumPy. This ensures that the code will generate the same random data every time you run it
data = [np.random.normal(0, std, 100) for std in range(1, 4)]
# np.random.normal(0, std, 100): Inside the loop, this function generates 100 random numbers from a normal distribution with a mean of 0 and a standard deviation of std (which takes the value of 1, 2, and 3 in each iteration). This creates three datasets with different levels of spread.

# Create a box plot
plt.boxplot(data, vert=True, patch_artist=True, labels=['Group 1', 'Group 2', 'Group 3'])
# vert = True sets the boxplot to vertical
# patch_artist = Truue allows you to customize the colors of the boxplot
plt.title("Box Plot")
plt.xlabel("Groups")
plt.ylabel("Values")
plt.show()

Output

Note that the center value of a boxplot represents the median, box size indicates how spread out the data is, bottom edge represents the first quartile, the top edge represents the third quartile and the lines extending out are called the whiskers. The small circles represent any outliers that may lie in the data.

Saving Plots

Lastly after generating all your plots you should be aware how to save the generated graphs.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.plot(x, y)
plt.title("Saving Plots")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.savefig('plot.png') # This saves the graph
plt.show()

Output

The generated image gets saved

You may have noticed us using the plt.show() command every time to display every graph, but there is a hack around it.

You can use the following command

%matplotlib inline

This magic command is specific to Jupyter notebooks. It tells the notebook to display Matplotlib plots inline, directly below the code cells that produce them.

If you run this command once then you dont have to use plt.show() command every time.

Congrats! You’ve mastered Matplotlib, and learned how to turn data into clear, beautiful visuals. Keep experimenting, and you’ll keep improving. Thanks for joining me in this journey and I hope you learned something today.

Python
Matplotlib
Matplotlib Tutorial
Data Science
Data Analysis
Recommended from ReadMedium