To create and share charts through Plotly's Chart Studio (web version), you can follow these steps:
1. Log in or register for Plotly Chart Studio
OpenPlotly Chart Studio.
If you don’t have an account, click “Sign Up” to register; if you already have an account, click “Log In” to log in.
2. Create a chart
After logging in, click the "Create" button in the upper right corner of the page.
Select "Chart" to create a new chart.
3. Upload data
On the chart creation page that opens, you can choose to upload a data file (such as CSV) or enter the data directly.
Click "Add Trace" and select "Type of Chart" as "Sunburst".
4. Configure charts
In the "Data" tab, configure the data source. For a sunburst chart, you need to configure the "Labels" and "Parents" fields.
In the Traces tab, select specific settings for the sunburst chart, such as color and hierarchy.
5. Save the chart
After the configuration is completed, click the "Save" button in the upper right corner of the page.
Enter a chart name and description, then click Save.
6. Generate embed code
After saving the chart, click the "Share" button in the upper right corner of the page.
In the pop-up menu, select the "Embed" option.
Copy the generated embed code.
7. Embed charts into Notion
Open Notion and navigate to the page where you want to insert the chart.
Create an "Embed" block:
In the dialog box that pops up, paste the embed code you copied from Plotly Chart Studio and click "Embed".
Through the above steps, you can embed an interactive sunburst chart in your Notion page. Doing so allows you to display and interact with chart content directly in Notion.
Sample code (generated in Python and uploaded to Plotly)
The following is a complete code example for generating a sunburst chart in Python and uploading it to Plotly Chart Studio:
python复制代码
import plotly.graph_objects as go
import chart_studio
import chart_studio.plotly as py
import chart_studio.tools as tls
输入您的Plotly账户信息
username = 'your_username'
api_key = 'your_api_key'
chart_studio.tools.set_credentials_file(username=username, api_key=api_key)
构建层次结构数据
data = {
"name": "云计算平台",
"children": [
{
"name": "AWS",
"children": [
{
"name": "容器技术",
"children": [
{
"name": "Kubernetes",
"children": [
{
"name": "攻击面",
"children": [
{"name": "AKSK攻击"},
{"name": "Kubernetes攻击"},
{"name": "CI/CD攻击"},
{"name": "Docker Swarm攻击"},
{"name": "eBPF攻击"}
]
},
{
"name": "防御措施",
"children": [
{"name": "网络隔离"},
{"name": "密钥防御"},
{"name": "Severless防护"},
{"name": "IAC扫描"},
{"name": "容器扫描"}
]
},
{
"name": "BAS平台",
"children": [
{"name": "虚拟攻击"},
{"name": "入侵"},
{"name": "服务器区攻击"},
{"name": "横向移动"},
{"name": "数据泄露"},
{"name": "攻击路线模拟"}
]
}
]
}
]
}
]
}
]
}
将层次结构数据转换为适合Plotly的数据格式
def get_sunburst_data(node, parent_name=""):
labels = []
parents = []
ids = []
def recurse(node, parent_name):
name = node["name"]
labels.append(name)
parents.append(parent_name)
ids.append(name)
for child in node.get("children", []):
recurse(child, name)
recurse(node, parent_name)
return labels, parents, ids
labels, parents, ids = get_sunburst_data(data)
绘制旭日图
fig = go.Figure(go.Sunburst(
labels=labels,
parents=parents,
ids=ids,
))
上传图表到Plotly Chart Studio
py.plot(fig, filename='Sunburst Chart', auto_open=True)
Comments (0)
Login to post a comment.