python画图代码大全
时间: 2023-07-22 17:22:04 浏览: 84
python中关于绘图的代码
以下是一些常用的 Python 画图库及其示例代码:
1. Matplotlib
```
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]
plt.plot(x, y)
plt.show()
```
2. Seaborn
```
import seaborn as sns
tips = sns.load_dataset("tips")
sns.scatterplot(x="total_bill", y="tip", hue="sex", data=tips)
```
3. Plotly
```
import plotly.express as px
df = px.data.gapminder().query("continent=='Oceania'")
fig = px.line(df, x="year", y="lifeExp", color='country')
fig.show()
```
4. Bokeh
```
from bokeh.plotting import figure, output_file, show
x = [1, 2, 3, 4, 5]
y = [10, 8, 6, 4, 2]
output_file("line.html")
p = figure(title="Line plot example")
p.line(x, y, legend_label="Line", line_width=2)
show(p)
```
5. ggplot
```
from ggplot import *
df = diamonds.head(1000)
ggplot(df, aes(x='price', y='carat', color='cut')) + \
geom_point() + \
labs(title="Diamonds dataset", x="Price", y="Carat")
```
这些库都有丰富的文档和示例供您参考。
阅读全文