Hướng dẫn subplot formatting python - Python định dạng subplot
Các hình với các ô con được tạo bằng hàm Dưới đây là một ví dụ về việc tạo ra một con số bao gồm hai dấu vết import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()5 nằm cạnh nhau vì có 2 cột và 1 hàng trong bố cục subplot. In [1]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1 ) fig.add_trace( go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Side By Side Subplots") fig.show() Subplots được xếp chồng lên nhauDưới đây là một ví dụ về việc tạo ra một hình với các ô con được xếp chồng lên nhau vì có 3 hàng và 1 cột trong bố cục subplot. In [2]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show() Nhiều lô conDưới đây là một ví dụ về việc tạo lưới phụ 2 x 2 và điền vào mỗi subplot với một dấu vết import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()5 duy nhất. In [3]: import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show() Nhiều ô phụ có tiêu đề ¶Đối số import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()7 có thể được sử dụng để định vị các chú thích văn bản làm tiêu đề cho mỗi subplot. Dưới đây là một ví dụ về việc thêm các tiêu đề Subplot vào lưới phụ 2 x 2 của dấu vết phân tán. In [4]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show() Subplots có chú thích BurIn [5]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show() Tùy chỉnh chiều rộng cột Subplot và độ cao hàngĐối số import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()9 có thể được sử dụng để tùy chỉnh độ rộng tương đối của các cột trong lưới Subplot. Nó nên được đặt thành một danh sách các số có độ dài phù hợp với đối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()1. Các số này sẽ được chuẩn hóa, do đó chúng tổng hợp thành 1 và được sử dụng để tính toán độ rộng tương đối của các cột lưới con. Đối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()2 phục vụ cùng một mục đích để kiểm soát chiều cao tương đối của các hàng trong lưới Subplot. Dưới đây là một ví dụ về việc tạo ra một con số với hai dấu vết phân tán ở các ô phụ bên cạnh. Subplot bên trái được đặt là rộng hơn bên phải. In [6]: import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show() Subplots in Dash¶Dash là cách tốt nhất để xây dựng các ứng dụng phân tích trong Python bằng cách sử dụng các số liệu thuần túy. Để chạy ứng dụng bên dưới, chạy from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()3, nhấp vào "Tải xuống" để lấy mã và chạy from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()4. Bắt đầu với các tài liệu Dash chính thức và tìm hiểu cách dễ dàng tạo kiểu và triển khai các ứng dụng như thế này với Dash Enterprise.learn how to effortlessly style & deploy apps like this with Dash Enterprise. Tùy chỉnh trục subplotSau khi một hình với các ô con được tạo bằng hàm import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()3, các thuộc tính trục của nó (Tiêu đề, Phông chữ, Phạm vi, Kiểu lưới, v.v.) có thể được tùy chỉnh bằng các phương thức đối tượng đồ thị from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()6 và from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()7. Theo mặc định, các phương pháp này áp dụng cho tất cả các trục X hoặc trục y trong hình. Các đối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()8 và from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()9 có thể được sử dụng để kiểm soát các trục nào được nhắm mục tiêu bởi bản cập nhật. Dưới đây là một ví dụ tạo ra một con số có lưới phụ 2 x 2, điền vào mỗi mẫu phụ với một dấu vết phân tán và sau đó cập nhật các tiêu đề trục X và Y cho mỗi subplot riêng lẻ. In [8]: from plotly.subplots import make_subplots import plotly.graph_objects as go # Initialize figure with subplots fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4") ) # Add traces fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) # Update xaxis properties fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1) fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2) fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1) fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2) # Update yaxis properties fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1) fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2) fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1) fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2) # Update title and height fig.update_layout(title_text="Customizing Subplot Axes", height=700) fig.show() Subplots với X-Aaxes được chia sẻĐối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()0 với import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()3 có thể được sử dụng để liên kết các trục x của các ô con trong hình kết quả. Đối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()2 được sử dụng để kiểm soát khoảng cách dọc giữa các hàng trong lưới con. Dưới đây là một ví dụ tạo ra một con số với 3 ô con xếp chồng lên theo chiều dọc với các trục X được liên kết. Một giá trị khoảng cách thẳng đứng nhỏ được sử dụng để giảm khoảng cách giữa các hàng subplot. In [9]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02) fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]), row=2, col=1) fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]), row=1, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots with Shared X-Axes") fig.show() Subplots với các trục y được chia sẻĐối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()3 với import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()3 có thể được sử dụng để liên kết các trục y của các ô con trong hình kết quả. Dưới đây là một ví dụ tạo ra một hình có lưới phụ 2 x 2, trong đó các trục y của mỗi hàng được liên kết. In [10]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=2, cols=2, shared_yaxes=True) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 3, 4]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[5, 5, 5]), row=1, col=2) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=600, width=600, title_text="Multiple Subplots with Shared Y-Axes") fig.show() Subplots với colorcalecale chungĐể chia sẻ thông tin về màu sắc trong nhiều ô con, bạn có thể sử dụng ColorAxis. In [11]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2, shared_yaxes=True) fig.add_trace(go.Bar(x=[1, 2, 3], y=[4, 5, 6], marker=dict(color=[4, 5, 6], coloraxis="coloraxis")), 1, 1) fig.add_trace(go.Bar(x=[1, 2, 3], y=[2, 3, 5], marker=dict(color=[2, 3, 5], coloraxis="coloraxis")), 1, 2) fig.update_layout(coloraxis=dict(colorscale='Bluered_r'), showlegend=False) fig.show() Subplot có kích thước tùy chỉnh với các tiêu đề phụĐối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()5 thành import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()3 được sử dụng để định cấu hình các tùy chọn trên mỗi subplot. from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()5 phải là danh sách 2 chiều với các kích thước phù hợp với các kích thước được cung cấp dưới dạng các đối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()8 và from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4")) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=500, width=700, title_text="Multiple Subplots with Titles") fig.show()1. Các phần tử của from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()5 có thể là import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show()1, cho thấy không có phần phụ nên được khởi tạo bắt đầu với ô lưới này hoặc từ điển chứa các tùy chọn Subplot. Tùy chọn Subplot import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show()2 chỉ định số lượng cột lưới mà Subplot bắt đầu trong ô đã cho sẽ chiếm. Nếu không xác định, import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show()2 mặc định là 1. Dưới đây là một ví dụ tạo ra lưới phụ 2 x 2 chứa 3 ô con. Phần tử Subplot from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()5 cho vị trí (2, 1) có giá trị import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show()2 là 2, khiến nó trải dài toàn bộ chiều rộng hình. Phần tử Subplot from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()5 cho vị trí (2, 2) là import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show()1 vì không có subplot bắt đầu tại vị trí này trong lưới. In [12]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()0 Nhiều lô phụ có kích thước tùy chỉnhNếu đối số import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show()8 thành import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()3 được đặt thành from plotly.subplots import make_subplots import plotly.graph_objects as go # Initialize figure with subplots fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4") ) # Add traces fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) # Update xaxis properties fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1) fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2) fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1) fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2) # Update yaxis properties fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1) fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2) fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1) fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2) # Update title and height fig.update_layout(title_text="Customizing Subplot Axes", height=700) fig.show()0, thì một biểu diễn văn bản của lưới phụ sẽ được in. Dưới đây là một ví dụ sử dụng các tùy chọn Subplot from plotly.subplots import make_subplots import plotly.graph_objects as go # Initialize figure with subplots fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4") ) # Add traces fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) # Update xaxis properties fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1) fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2) fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1) fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2) # Update yaxis properties fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1) fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2) fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1) fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2) # Update title and height fig.update_layout(title_text="Customizing Subplot Axes", height=700) fig.show()1 và import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show()2 để tạo bố cục Subplot tùy chỉnh với các ô phụ có kích thước hỗn hợp. Đối số import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2, column_widths=[0.7, 0.3]) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.show()8 được đặt thành from plotly.subplots import make_subplots import plotly.graph_objects as go # Initialize figure with subplots fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4") ) # Add traces fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) # Update xaxis properties fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1) fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2) fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1) fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2) # Update yaxis properties fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1) fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2) fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1) fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2) # Update title and height fig.update_layout(title_text="Customizing Subplot Axes", height=700) fig.show()0 để lưới phụ được in lên màn hình. In [13]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()1 from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()2 Các loại phụTheo mặc định, hàm import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()3 giả định rằng các dấu vết sẽ được thêm vào tất cả các ô con là dấu vết của Cartesian 2 chiều (ví dụ: import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()5, from plotly.subplots import make_subplots import plotly.graph_objects as go # Initialize figure with subplots fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4") ) # Add traces fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) # Update xaxis properties fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1) fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2) fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1) fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2) # Update yaxis properties fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1) fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2) fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1) fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2) # Update title and height fig.update_layout(title_text="Customizing Subplot Axes", height=700) fig.show()7, from plotly.subplots import make_subplots import plotly.graph_objects as go # Initialize figure with subplots fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4") ) # Add traces fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) # Update xaxis properties fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1) fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2) fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1) fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2) # Update yaxis properties fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1) fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2) fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1) fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2) # Update title and height fig.update_layout(title_text="Customizing Subplot Axes", height=700) fig.show()8, from plotly.subplots import make_subplots import plotly.graph_objects as go # Initialize figure with subplots fig = make_subplots( rows=2, cols=2, subplot_titles=("Plot 1", "Plot 2", "Plot 3", "Plot 4") ) # Add traces fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) # Update xaxis properties fig.update_xaxes(title_text="xaxis 1 title", row=1, col=1) fig.update_xaxes(title_text="xaxis 2 title", range=[10, 50], row=1, col=2) fig.update_xaxes(title_text="xaxis 3 title", showgrid=False, row=2, col=1) fig.update_xaxes(title_text="xaxis 4 title", type="log", row=2, col=2) # Update yaxis properties fig.update_yaxes(title_text="yaxis 1 title", row=1, col=1) fig.update_yaxes(title_text="yaxis 2 title", range=[40, 80], row=1, col=2) fig.update_yaxes(title_text="yaxis 3 title", showgrid=False, row=2, col=1) fig.update_yaxes(title_text="yaxis 4 title", row=2, col=2) # Update title and height fig.update_layout(title_text="Customizing Subplot Axes", height=700) fig.show()9, v.v.). Dấu vết với các loại subplot khác (ví dụ: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02) fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]), row=2, col=1) fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]), row=1, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots with Shared X-Axes") fig.show()0, from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02) fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]), row=2, col=1) fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]), row=1, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots with Shared X-Axes") fig.show()1, from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02) fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]), row=2, col=1) fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]), row=1, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots with Shared X-Axes") fig.show()2, v.v.) được hỗ trợ bằng cách chỉ định tùy chọn Subplot ____73 trong đối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode="markers+text", text=["Text A", "Text B", "Text C"], textposition="bottom center" ), row=1, col=1 ) fig.add_trace( go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode="markers+text", text=["Text D", "Text E", "Text F"], textposition="bottom center" ), row=1, col=2 ) fig.update_layout(height=600, width=800, title_text="Subplots with Annotations") fig.show()5 thành import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()3. Dưới đây là các giá trị có thể cho tùy chọn from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02) fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]), row=2, col=1) fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]), row=1, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots with Shared X-Axes") fig.show()3:
Dưới đây là một ví dụ tạo ra và điền vào lưới phụ 2 x 2 chứa 4 loại phụ khác nhau. Trong & nbsp; [14]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()3 Thay thế để cung cấp tên của một loại phụ (ví dụ: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02) fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]), row=2, col=1) fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]), row=1, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots with Shared X-Axes") fig.show()7, from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=2, cols=2, shared_yaxes=True) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 3, 4]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[5, 5, 5]), row=1, col=2) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=600, width=600, title_text="Multiple Subplots with Shared Y-Axes") fig.show()0, from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=2, cols=2, shared_yaxes=True) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 3, 4]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[5, 5, 5]), row=1, col=2) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=600, width=600, title_text="Multiple Subplots with Shared Y-Axes") fig.show()3, from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02) fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]), row=2, col=1) fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]), row=1, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots with Shared X-Axes") fig.show()9, v.v.), tùy chọn from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.02) fig.add_trace(go.Scatter(x=[0, 1, 2], y=[10, 11, 12]), row=3, col=1) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[100, 110, 120]), row=2, col=1) fig.add_trace(go.Scatter(x=[3, 4, 5], y=[1000, 1100, 1200]), row=1, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots with Shared X-Axes") fig.show()3 cũng có thể được đặt thành một chuỗi có chứa tên của loại theo dõi (ví dụ: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=2, cols=2, shared_yaxes=True) fig.add_trace(go.Scatter(x=[1, 2, 3], y=[2, 3, 4]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[5, 5, 5]), row=1, col=2) fig.add_trace(go.Scatter(x=[2, 3, 4], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.update_layout(height=600, width=600, title_text="Multiple Subplots with Shared Y-Axes") fig.show()4, ____99 , v.v.), sẽ được sử dụng để xác định loại phụ tương thích với dấu vết đó. Dưới đây là ví dụ trên, được sửa đổi để chỉ định các loại Subplot bằng tên loại Trace. In [15]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()4 Bên cạnh phụ (API cấp thấp) ¶In [16]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()5 Subplots với các trục được chia sẻ (API cấp thấp) ¶In [17]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()6 Các ô phụ được xếp chồng với trục X được chia sẻ (API cấp thấp) ¶In [18]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()7 Đặt các ô con trên hình trực tiếp JoMới trong 4.13 Các ô con có thể được thêm vào một con số đã có, miễn là nó chưa có các ô phụ. from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2, shared_yaxes=True) fig.add_trace(go.Bar(x=[1, 2, 3], y=[4, 5, 6], marker=dict(color=[4, 5, 6], coloraxis="coloraxis")), 1, 1) fig.add_trace(go.Bar(x=[1, 2, 3], y=[2, 3, 5], marker=dict(color=[2, 3, 5], coloraxis="coloraxis")), 1, 2) fig.update_layout(coloraxis=dict(colorscale='Bluered_r'), showlegend=False) fig.show()7 chấp nhận tất cả các đối số giống như from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2, shared_yaxes=True) fig.add_trace(go.Bar(x=[1, 2, 3], y=[4, 5, 6], marker=dict(color=[4, 5, 6], coloraxis="coloraxis")), 1, 1) fig.add_trace(go.Bar(x=[1, 2, 3], y=[2, 3, 5], marker=dict(color=[2, 3, 5], coloraxis="coloraxis")), 1, 2) fig.update_layout(coloraxis=dict(colorscale='Bluered_r'), showlegend=False) fig.show()8. In [19]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()8 In [20]: from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()9 Trong & nbsp; [21]: import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()0 import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()1 Còn Dash thì sao? ¶Dash là một khung nguồn mở để xây dựng các ứng dụng phân tích, không cần JavaScript và nó được tích hợp chặt chẽ với thư viện đồ thị đồ họa. Tìm hiểu về cách cài đặt Dash tại https://dash.plot.ly/installation. Ở mọi nơi trong trang này mà bạn thấy from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2, shared_yaxes=True) fig.add_trace(go.Bar(x=[1, 2, 3], y=[4, 5, 6], marker=dict(color=[4, 5, 6], coloraxis="coloraxis")), 1, 1) fig.add_trace(go.Bar(x=[1, 2, 3], y=[2, 3, 5], marker=dict(color=[2, 3, 5], coloraxis="coloraxis")), 1, 2) fig.update_layout(coloraxis=dict(colorscale='Bluered_r'), showlegend=False) fig.show()9, bạn có thể hiển thị cùng một hình trong một ứng dụng Dash bằng cách chuyển nó sang đối số from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()00 của thành phần from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()01 từ gói from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=3, cols=1) fig.append_trace(go.Scatter( x=[3, 4, 5], y=[1000, 1100, 1200], ), row=1, col=1) fig.append_trace(go.Scatter( x=[2, 3, 4], y=[100, 110, 120], ), row=2, col=1) fig.append_trace(go.Scatter( x=[0, 1, 2], y=[10, 11, 12] ), row=3, col=1) fig.update_layout(height=600, width=600, title_text="Stacked Subplots") fig.show()02 tích hợp như thế này: import plotly.graph_objects as go from plotly.subplots import make_subplots fig = make_subplots(rows=2, cols=2, start_cell="bottom-left") fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1) fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2) fig.add_trace(go.Scatter(x=[300, 400, 500], y=[600, 700, 800]), row=2, col=1) fig.add_trace(go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000]), row=2, col=2) fig.show()2 |