jupter中将数据可视化
时间: 2023-12-02 22:06:25 浏览: 82
Jupyter Notebook中可以使用多种Python可视化库进行数据可视化,以下是其中一些常用的库和用法:
1. Matplotlib:用于绘制静态图表,例如折线图、散点图、柱状图等。
```python
import matplotlib.pyplot as plt
%matplotlib inline
# 绘制折线图
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
# 绘制散点图
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.scatter(x, y)
# 绘制柱状图
x = ['A', 'B', 'C', 'D', 'E']
y = [2, 4, 6, 8, 10]
plt.bar(x, y)
```
2. Seaborn:基于Matplotlib的高级可视化库,用于绘制统计图形,例如热力图、箱线图、核密度图等。
```python
import seaborn as sns
%matplotlib inline
# 绘制热力图
flights = sns.load_dataset('flights')
flights = flights.pivot('month', 'year', 'passengers')
sns.heatmap(flights)
# 绘制箱线图
tips = sns.load_dataset('tips')
sns.boxplot(x='day', y='total_bill', data=tips)
# 绘制核密度图
iris = sns.load_dataset('iris')
sns.kdeplot(data=iris, x='sepal_length', hue='species')
```
3. Plotly:用于绘制交互式图表,例如线图、散点图、热力图等。
```python
import plotly.express as px
# 绘制线图
df = px.data.gapminder()
fig = px.line(df, x='year', y='lifeExp', color='continent')
fig.show()
# 绘制散点图
df = px.data.iris()
fig = px.scatter(df, x='sepal_width', y='sepal_length', color='species')
fig.show()
# 绘制热力图
df = px.data.tips()
fig = px.density_heatmap(df, x='total_bill', y='tip')
fig.show()
```
这些只是其中的一部分可视化库和用法,你可以根据实际情况选择适合自己的库和方法。
阅读全文
相关推荐
















