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

歡迎訪問 生活随笔!

生活随笔

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

python

python 定义变量x格式_如何从CSV文件中提取数据列并将它们定义为x和y变量,然后使用pylab在python中绘制它们?...

發布時間:2025/3/21 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 定义变量x格式_如何从CSV文件中提取数据列并将它们定义为x和y变量,然后使用pylab在python中绘制它们?... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我知道這篇文章已經過時了;但是,對于需要快速繪制csv數據的人來說,下面的腳本將提供一個很好的解決方案。

它展示了如何從csv文件導入數據,以及如何使用matplotlib繪制一個png并打印出來。

使用沒有標題的Lake Huron的數據,可以得到一個很好的繪圖。import csv

import matplotlib.pyplot as plt

from numpy import arange

#####################################

# instatiation of variables

filehandle = "lake_huron.csv"

x_data = [] # makes a list

y_data = [] # makes a list

png_filename = 'LakeData.png'

#####################################

# opening csv file and reading

my_file = open(filehandle, "rb") # opens file for reading

data = csv.reader(my_file) # saves file to variable "data"

#####################################

# saves csv data to x_data and y_data

for row in data:

x_data.append(eval(row[1])) # selects data from the ith row

y_data.append(eval(row[2])) # selects data from the ith row

#####################################

# closes csv file

my_file.close() # closes file

#####################################

# makes plot (show) and saves png

fig = plt.figure() # calls a variable for the png info

# defines plot's information (more options can be seen on matplotlib website)

plt.title("Level of Lake Huron from 1875 to 1972") # plot name

plt.xlabel('Year') # x axis label

plt.ylabel('Lake Level (in feet)') # y axis label

plt.xticks(arange(1875,1973,10)) # x axis tick marks

plt.axis([1875,1973,573,584]) # x and y ranges

# defines png size

fig.set_size_inches(10.5,5.5) # png size in inches

# plots the data from the csv above

plt.plot(x_data,y_data)

#saves png with specific resolution and shows plot

fig.savefig(png_filename ,dpi=600, bbox_inches='tight') # saves png

plt.show() # shows plot

plt.close() # closes pylab

總結

以上是生活随笔為你收集整理的python 定义变量x格式_如何从CSV文件中提取数据列并将它们定义为x和y变量,然后使用pylab在python中绘制它们?...的全部內容,希望文章能夠幫你解決所遇到的問題。

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