日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

【Python Matplotlib】線設置,坐標顯示范圍

 imelee 2016-12-18

改變線的顏色和線寬

參考文章:

線有很多屬性你可以設置:線寬,線型,抗鋸齒等等;具體請參考matplotlib.lines.Line2D

有以下幾種方式可以設置線的屬性

  • 使用關鍵字參數

    plt.plot(x, y, linewidth=2.0)

  • 使用 Line2D 對象的設置方法。 plot 返回一個 Line2D 對象的列表; line1, line2 = plot(x1, y1, x2, y2)。 下面的代碼中我們假定圖中僅有一條線以使返回的列表的長度為1。我們使用 line, 進行元組展開,來獲得列表的首個元素。

    line, = plt.plot(x, y, '-')
    line.set_antialiased(False) # 關閉抗鋸齒
    
  • 使用 setp() 命令。下面給出的例子使用Matlab樣式命令來設置對列表中的線對象設置多種屬性。 setp可以作用于對象列表或僅僅一個對象。你可以使用Python關鍵字的形式或Matlab樣式。

    lines = plt.plot(x1, y1, x2, y2)
    # use keyword args
    plt.setp(lines, color='r', linewidth=2.0)
    # or MATLAB style string value pairs
    plt.setp(lines, 'color', 'r', 'linewidth', 2.0)
    

設置坐標軸范圍

參考文檔:

下面以 xlim() 為例進行說明:

獲取或設置當前圖像 x 軸的范圍:

xmin, xmax = xlim()   # return the current xlim
xlim( (xmin, xmax) )  # set the xlim to xmin, xmax
xlim( xmin, xmax )    # set the xlim to xmin, xmax

或者可以下面這樣:

xlim(xmax=3) # adjust the max leaving min unchanged
xlim(xmin=1) # adjust the min leaving max unchanged

設置 x-axis limits 會使得 autoscaling 自動關閉,即兩者不能同時設置。

以上說明綜合舉例如下:

import numpy as np
import matplotlib.pyplot as plt

plt.figure(figsize=(8, 5), dpi=80)
plt.subplot(111)

X = np.linspace(-np.pi, np.pi, 256, endpoint=True)
S = np.sin(X)
C = np.cos(X)

plt.plot(X, C, color="blue", linewidth=2.5, linestyle="-")
plt.plot(X, S, color="red", linewidth=2.5, linestyle="-")

plt.xlim(X.min() * 1.1, X.max() * 1.1)
plt.ylim(C.min() * 1.1, C.max() * 1.1)

plt.show()

生成的圖像:

【Python <wbr>Matplotlib】線設置,坐標顯示范圍

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多