天天看點

越覽(14)——Matlab學習筆記(1):繪制二維圖

作者:LearningYard學苑
越覽(14)——Matlab學習筆記(1):繪制二維圖

分享興趣,傳播快樂,

增長見聞,留下美好。

親愛的您,這裡是LearningYard學苑!

今天小編為大家帶來文章“越覽(14)——Matlab學習筆記(1):繪制二維圖。”

歡迎您的通路。

Share interest, spread happiness,

increase knowledge,and leave beautiful.

Dear, this is LearningYard Academy!

Today, the editor brings you the article “Yue Lan (14):

Matlab Study Notes (1): Drawing 2D Diagrams.”

Welcome to visit!

一、思維導圖(Mind Maps)

越覽(14)——Matlab學習筆記(1):繪制二維圖

二、資料圖像繪制簡介(Introduction to Data Image Rendering)

資料可視化的目的在于,通過圖形從将一堆雜亂的離散資料中觀察資料間的内在關系,感受由土星所傳遞的内在的本質。Matlab特别注重資料的圖形表示,并不斷地采用新技術改進,并完備其可視化功能。

The purpose of data lake visualization is to observe the internal relationship between data through graphs from a bunch of messy discrete data, and feel the inherent essence conveyed by Saturn. Matlab pays special attention to the graphical representation of data, and constantly adopts new technologies to improve and complete its visualization functions.

三、二維圖的繪制方法(Drawing method of two-dimensional graph)

(一)基本文法(Basic grammar)

Plot函數是用于繪制二維圖形的核心工具,它可以幫助使用者直覺展示資料點之間的關系,或者描繪數學函數的變化趨勢。

The Plot function is a core tool for drawing two-dimensional graphs, which can help users visualize the relationship between data points or depict the changing trend of mathematical functions.

plot(X,Y)可以用來建立 Y 中資料對 X 中對應值的二維線圖。

Plot (X, Y) can be used to create a two-dimensional line plot of the data in Y against the corresponding values in X.

plot(X1,Y1,...,Xn,Yn) 可在同一組坐标軸上繪制多對 x 和 y 坐标。此文法可替代将坐标指定為矩陣的形式。

Plot (X1, Y1,..., Xn, Yn) plots multiple pairs of x and y coordinates on the same set of axes. This syntax is an alternative to specifying the coordinates as a matrix.

使用plot函數繪圖時,先要取得x、 y坐标,然後再繪制曲線,x往往采取等間隔采樣。在實際應用中,函數随着自變量的變化趨勢未知,或者在不同區間函數頻率特性差别大,此時使用plot函數繪制圖形,如果自變量的采樣間隔設定不合理,則無法反映函數的變化趨勢。

When using the plot function to plot, first obtain the x and y coordinates, and then draw the curve. X is often sampled at equal intervals. In practical applications, the trend of the function with the independent variable is unknown, or the frequency characteristics of the function vary greatly in different intervals. At this time, the plot function is used to plot graphs. If the sampling interval of the independent variable is set irrationally, the change trend of the function cannot be reflected.

(二)執行個體操作(Instance operation)

在MATLAB中繪制二維圖是一項基本且常用的功能,可以通過多種内置函數實作。接下來為大家介紹具體的繪制方法。

Drawing two-dimensional diagrams in MATLAB is a basic and commonly used function, which can be realized through a variety of built-in functions. Next, I will introduce the specific drawing method for you.

1.建立圖像(Create image)

首先,建立一個變量x,它是介于0-5之間(每隔0.1取一個點)。在同一坐标系中繪制關于變量x的三條線。

First, create a variable x that is between 0 and 5 (taking a point every 0.1). Draw three lines about the variable x in the same coordinate system.

代碼如下:

Code show as below:

越覽(14)——Matlab學習筆記(1):繪制二維圖

運作結果如下:

The results are as follows:

越覽(14)——Matlab學習筆記(1):繪制二維圖

2.圖像的修飾(Retouching of images)

在MATLAB中,修飾二維圖像線條可以通過多種方式實作,包括但不限于改變線條顔色、線型、标記符号、以及添加圖例、标題、軸标簽等。以下是一些基本的步驟和示例代碼,展示如何進行這些修飾:

In MATLAB, modifying the lines of a 2D image can be done in a number of ways, including but not limited to changing the line color, line shape, marking symbols, and adding legends, captions, axis labels, etc. Here are some basic steps and sample code to show how to make these modifications:

(1)線條顔色與線型(Line color and line shape)

可以使用顔色名稱或RGB值來指定線條顔色,将y1設定成黑色,y2設定成紅色,y3設定成藍色,再修改一下線型或資料點型。組合方式為‘色彩+線型’或‘色彩+點型’。

You can use the color name or RGB value to specify the line color, set y1 to black, y2 to red, y3 to blue, and modify the line or data point type. The combination method is'color + line type 'or'color + point type'.

代碼如下:

Code show as below:

越覽(14)——Matlab學習筆記(1):繪制二維圖

運作結果如下:

The results are as follows:

越覽(14)——Matlab學習筆記(1):繪制二維圖

(2)添加文本注釋(Add text comments)

gtext和text都是用于在圖形中添加文本注釋的函數,但它們的工作方式略有不同。gtext函數允許使用者通過滑鼠互動來放置文本。text函數允許你以程式設計方式在圖形中指定的坐标(x, y)處添加文本字元串。這裡的x和y是數值,它們定義了文本在圖中的位置。

Both gtext and text are functions for adding text annotations to a graph, but they work slightly differently. The gtext function allows users to place text via mouse interaction. The text function allows you to programmatically add a text string at the coordinates (x, y) specified in the graph. Here x and y are numeric values that define the position of the text in the graph.

越覽(14)——Matlab學習筆記(1):繪制二維圖

(3)添加軸标簽(Add axis label)

在MATLAB中,’xlabel’,‘ylabel’,和 ‘zlabel’分别是用來給二維或三維圖形的x軸、y軸、z軸添加标簽的函數,用于标注坐标軸所代表的變量名稱或其他說明資訊。

In MATLAB, 'xlabel', 'ylabel', and'zlabel 'are functions used to label the x-axis, y-axis, and z-axis of a two-dimensional or three-dimensional graph, respectively, to label the variable names or other descriptive information represented by the coordinate axes.

給剛剛所繪制的圖添加軸标簽:

Add axis labels to the diagram just drawn:

越覽(14)——Matlab學習筆記(1):繪制二維圖

(4)添加圖例(Add legend)

legend函數用于建立圖表的圖例,它可以幫助标注圖表中不同線條或标記所代表的含義。

The legend function is used to create the legend of a chart, which can help to label the meanings of different lines or markers in the chart.

越覽(14)——Matlab學習筆記(1):繪制二維圖

學會了的話,不妨現在就動手試試吧。

If you've learned it, you might as well try it now.

今天的分享就到這裡了。

如果您對文章有獨特的想法,

歡迎給我們留言,

讓我們相約明天。

祝您今天過得開心快樂!

That's all for today's sharing.

If you have a unique idea about the article,

please leave us a message,

and let us meet tomorrow.

I wish you a nice day!

文案|yyz

排版|yyz

稽核|hzy

翻譯:ChatGPT

參考資料:哔哩哔哩、CSDN部落格

本文由LearningYard學苑整理發出,如有侵權請在背景留言!