[英]How can I change my code to print only x amount of graphs?
下面是我的代碼:
import pandas as pd
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
df = pd.read_csv(r"/Users/aaronhuang/Desktop/ffp/exfileCLEAN2.csv", skiprows=[1]) # replace.
this with wherever the file is.
magnitudes = df['Magnitude '].values
times = df['Time '].values
zscores = np.abs(stats.zscore(magnitudes, ddof=1))
outlier_indicies = np.argwhere(zscores > 3).flatten()
print(times[outlier_indicies])
import matplotlib.pyplot as plt
fig, axes = plt.subplots(6, 10, figsize=(30,30))
for i in range(6):
for j in range(10):
x = df.iloc[j*10:(j+1)*10,:]
axes[i][j].plot(x['Time '], x['Magnitude '])
axes[i][j].set_xticklabels(x['Time '], rotation=45)
plt.show()
它一次打印所有圖表(60),我怎樣才能將其更改為打印更少,例如 30 個圖表?
你必須改變這 3 行。
fig, axes = plt.subplots(6, 10, figsize=(30,30))
for i in range(6):
for j in range(10):
他們正在運行 6 * 10 所以總共60
。 如果你想要例如 50 你把它改成
fig, axes = plt.subplots(5, 10, figsize=(30,30))
for i in range(5):
for j in range(10):
因此,您必須更改range()
和subplots()
中的參數。
更好的方法是聲明兩個變量來控制大小,如下所示:
width = 5
height = 10
fig, axes = plt.subplots(width, height, figsize=(30,30))
for i in range(width):
for j in range(height):
現在您可以通過更改兩個變量的值來簡單地更改比例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.