日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python:matplotlib绘图

發布時間:2024/5/17 python 391 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python:matplotlib绘图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.Python:matplotlib繪圖時指定圖像大小,放大圖像

matplotlib繪圖時是默認的大小,有時候默認的大小會感覺圖片里的內容都被壓縮了,解決方法如下。
先是原始代碼:

1

2

3

4

5

6

7

from?matplotlib?import?pyplot as plt

?

plt.figure(figsize=(1,1)) #單位是英寸

?

x?=?[1,2,3]

plt.plot(x, x)

plt.show()

  

關鍵的代碼是plt.figure(figsize=(1,1)),生成的圖片如下

修改代碼,放大圖片:

1

2

3

4

5

6

7

from?matplotlib?import?pyplot as plt

?

plt.figure(figsize=(10,10))

?

x?=?[1,2,3]

plt.plot(x, x)

plt.show()

  

這時候橫坐標和縱坐標都放大了10倍:

如果想要指定像素,可以這么做:

1

2

3

4

5

6

7

from?matplotlib?import?pyplot as plt

?

plt.figure(dpi=80)

?

x?=?[1,2,3]

plt.plot(x, x)

plt.show()

  

?

2.Python:matplotlib繪圖-scatter 散點圖

https://matplotlib.org/gallery/lines_bars_and_markers/scatter_custom_symbol.html#sphx-glr-gallery-lines-bars-and-markers-scatter-custom-symbol-py

import matplotlib.pyplot as plt import numpy as np# unit area ellipse rx, ry = 3., 1. area = rx * ry * np.pi theta = np.arange(0, 2 * np.pi + 0.01, 0.1) verts = np.column_stack([rx / area * np.cos(theta), ry / area * np.sin(theta)])x, y, s, c = np.random.rand(4, 30) s *= 10**2.fig, ax = plt.subplots() ax.scatter(x, y, s, c, marker=verts)plt.show()

?

總結

以上是生活随笔為你收集整理的Python:matplotlib绘图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。