Bạn đã đi đúng hướng với pd.concat
và pd.melt
, sau đó là Seaborn relplot
. Tôi sẽ tiếp cận nó như thế này:
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["key"], var_name="station", value_name="station_value", ignore_index = False]
#plotting - the datetime conversion might not be necessary
#depending on the datetime format of your original dataframes
#best approach is conversion to datetime index when creating the dataframes
fg = sns.relplot[data=df, x = pd.to_datetime[df.index.to_timestamp[]], y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
Đầu ra mẫu:
Nếu phiên bản Pandas không thể xử lý các mục nhập chỉ mục trùng lặp, chúng ta có thể viết lại nó thành:
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
Điều kiện tiên quyết: matplotlib: Matplotlib
Trong matplotlib, chúng ta có thể vẽ nhiều biểu đồ trong một lô theo hai cách. Một là bằng cách sử dụng hàm Subplot [] và các hàm khác bằng cách chồng chất của biểu đồ thứ hai trên i.e đầu tiên, tất cả các biểu đồ sẽ xuất hiện trên cùng một lô. Chúng tôi sẽ xem xét cả hai cách từng người một.
Nhiều sơ đồ sử dụng hàm Subplot []
Hàm Subplot [] là hàm trình bao bọc cho phép lập trình viên vẽ nhiều hơn một biểu đồ trong một hình bằng cách gọi nó một lần.
Cú pháp: matplotlib.pyplot.subplots [nrows = 1, ncols = 1, sharex = false, sharey = false, squeeze = true, subplot_kw = none matplotlib.pyplot.subplots[nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw]
Parameters:
- NROWS, NCOLS: & NBSP; Chúng cung cấp số lượng hàng và cột & nbsp; tương ứng. Ngoài ra, phải lưu ý rằng cả hai tham số này đều là tùy chọn và giá trị mặc định là 1. These gives the number of rows and columns respectively. Also, it must be noted that both these parameters are optional and the default value is 1.
- chia sẻ, chia sẻ: & nbsp; Các tham số này chỉ định về các thuộc tính được chia sẻ giữa các giá trị A và Y.Possible cho chúng có thể là, hàng, col, không có hoặc giá trị mặc định là sai. These parameters specify about the properties that are shared among a and y axis.Possible values for them can be, row, col, none or default value which is False.
- Squeeze: & nbsp; Tham số này là một giá trị boolean được chỉ định, yêu cầu lập trình viên có nên vắt ra hay không, có nghĩa là loại bỏ kích thước phụ khỏi mảng. Nó có một giá trị mặc định sai.This parameter is a boolean value specified, which asks the programmer whether to squeeze out, meaning remove the extra dimension from the array. It has a default value False.
- subplot_kw: Các tham số này cho phép chúng tôi thêm các từ khóa vào mỗi subplot và giá trị mặc định của nó là không có.This parameters allow us to add keywords to each subplot and its default value is None.
- GridSpec_kw: Điều này cho phép chúng tôi thêm lưới trên mỗi subplot và có giá trị mặc định là không có.This allows us to add grids on each subplot and has a default value of None.
- ** FIG_KW: Điều này cho phép chúng tôi chuyển bất kỳ đối số từ khóa bổ sung nào khác cho cuộc gọi chức năng và có giá trị mặc định là không có.This allows us to pass any other additional keyword argument to the function call and has a default value of None.
Thí dụ :
Python3
import
matplotlib.pyplot as plt
import
numpy as np
import
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
0import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
1import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2 import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
3import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
5import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
6import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
7import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
9pd.concat
0import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
83import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2 pd.concat
3import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
86import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2 pd.concat
6import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
89import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
91import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
92__12Đầu ra
đường cong chức năng sin và cosine trong một biểu đồ
relplot
0
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4relplot
4relplot
0
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4relplot
9import
0pd.concat
0relplot
0
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import
5import
6Làm thế nào để bạn vẽ nhiều biến trong một biểu đồ trong Python?
relplot
0import
5
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4matplotlib.pyplot as plt
8relplot
0import
5
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4relplot
9import
4pd.concat
0relplot
0import
5
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import
5numpy as np
0relplot
0import
5
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import
5relplot
9numpy as np
6pd.concat
0numpy as np
8
Đầu ra
đường cong chức năng sin và cosine trong một biểu đồ
Làm thế nào để bạn vẽ nhiều biến trong một biểu đồ trong Python?
Trong matplotlib, chúng ta có thể vẽ nhiều biểu đồ trong một lô theo hai cách ..
NROWS, NCOLS: Chúng cung cấp số lượng hàng và cột tương ứng. ....matplotlib.pyplot.subplot2grid[shape, loc, rowspan=1, colspan=1, fig=None, **kwargs]
Parameter:
- Tham số Shapethis là một chuỗi gồm hai giá trị số nguyên cho biết hình dạng của lưới mà chúng ta cần đặt các trục. Mục đầu tiên là cho hàng, trong khi mục thứ hai là dành cho cột.
This parameter is a sequence of two integer values which tells the shape of the grid for which we need to place the axes. The first entry is for row, whereas the second entry is for column.- Tham số hình dạng locus, thậm chí IOC là một chuỗi gồm 2 giá trị số nguyên, trong đó mục đầu tiên vẫn còn cho hàng và thứ hai là để cột đặt trục trong lưới.
Like shape parameter, even Ioc is a sequence of 2 integer values, where first entry remains for the row and the second is for column to place axis within grid.- Tham số Rowspanthis lấy giá trị nguyên và số cho biết số lượng hàng cho trục kéo dài hoặc tăng về phía bên phải.
This parameter takes integer value and the number which indicates the number of rows for the axis to span to or increase towards right side.- Tham số colspanthis lấy giá trị số nguyên và số cho biết số lượng cột cho trục kéo dài hoặc tăng độ dài xuống.
This parameter takes integer value and the number which indicates the number of columns for the axis to span to or increase the length downwards.- Figthis là một tham số tùy chọn và đưa hình để đặt trục vào. Nó mặc định là hình hiện tại.
This is an optional parameter and takes Figure to place axis in. It defaults to current figure.- ** kwargsthis cho phép chúng tôi chuyển bất kỳ đối số từ khóa bổ sung nào khác cho cuộc gọi hàm và có giá trị mặc định là không có.
This allows us to pass any other additional keyword argument to the function call and has a default value of None.
Thí dụ :
Python3
import
matplotlib.pyplot as plt
import
numpy as np
import
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
0Is
Is
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
26import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2 import
7import
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
01import
5import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
19__12import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
40import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2 import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
3import
5import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
45pd.concat
0import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
47import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
6import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
6import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
50pd.concat
0import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
52import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
53pd.concat
0import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
55import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
56import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
57pd.concat
0import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
59import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
6import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
61import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
62import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
63pd.concat
0import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
65numpy as np
8
Đầu ra
Nhiều sơ đồ sử dụng hàm subplot2Grid []
Âm mưu trong cùng một cốt truyện
Bây giờ chúng ta đã tìm hiểu về việc vẽ nhiều biểu đồ bằng cách sử dụng hàm Subplot và subplot2Grid của thư viện matplotlib. Như đã đề cập trước đó, bây giờ chúng ta sẽ xem xét âm mưu nhiều đường cong bằng cách chồng chất chúng. Trong phương pháp này, chúng tôi không sử dụng bất kỳ chức năng đặc biệt nào thay vì chúng tôi trực tiếp vẽ các đường cong trên nhau và cố gắng đặt tỷ lệ.
Thí dụ :
Python3
import
matplotlib.pyplot as plt
import
numpy as np
import
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
0Is
Is
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
26import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2 import
7import
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
01import
5import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
4import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
19__12import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
40import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2 import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
3import
5import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
8import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
45pd.concat
0import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
96import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
98import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
92import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
#data generation
import numpy as np
np.random.seed[123]
date_range = pd.period_range['1981-01-01','1981-01-04',freq='D']
x = np.random.randint[1, 10, [4,2]]
y = np.random.randint[1, 10, [4,2]]
x = pd.DataFrame[x, index = date_range, columns = ['station1','station2']]
y = pd.DataFrame[y, index = date_range + pd.to_timedelta[1, unit="D"], columns = ['station1','station2']]
#keep information where each data point comes from
x["key"], y["key"] = "x", "y"
#moving index into a column
x = x.reset_index[]
y = y.reset_index[]
#and changing it to datetime values that seaborn can understand
#only necessary because your example contains pd.Period data
x["index"] = pd.to_datetime[x["index"].astype[str]]
y["index"] = pd.to_datetime[y["index"].astype[str]]
#combining dataframes and reshaping
df = pd.concat[[x, y]].melt[["index", "key"], var_name="station", value_name="station_value"]
#plotting
fg = sns.relplot[data=df, x = "index", y = "station_value", kind = "line", hue = "key", row = "station"]
#shouldn't be necessary but this example had too many ticks for the interval
from matplotlib.dates import DateFormatter, DayLocator
fg.axes[0,0].xaxis.set_major_locator[DayLocator[interval=1]]
fg.axes[0,0].xaxis.set_major_formatter[DateFormatter["%y-%m-%d"]]
plt.show[]
2pd.concat
01pd.concat
0pd.concat
03pd.concat
04pd.concat
0
pd.concat
06pd.concat
07pd.concat
0
pd.concat
09pd.concat
10pd.concat
0
pd.concat
12
numpy as np
8
Đầu ra
Nhiều sơ đồ sử dụng hàm subplot2Grid []