python画图代码大全
时间: 2023-10-13 13:24:10 浏览: 75
以下是一些常见的 Python 画图库及其代码示例:
1. Matplotlib
```python
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
plt.plot(x, y)
plt.title('Sine wave')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()
```
2. Seaborn
```python
import seaborn as sns
import pandas as pd
df = pd.read_csv('data.csv')
sns.scatterplot(x='x', y='y', data=df)
```
3. Plotly
```python
import plotly.graph_objs as go
x = [1, 2, 3, 4, 5]
y = [2, 4, 1, 3, 5]
fig = go.Figure(data=go.Scatter(x=x, y=y))
fig.show()
```
4. Bokeh
```python
from bokeh.plotting import figure, output_file, show
x = [1, 2, 3, 4, 5]
y = [2, 4, 1, 3, 5]
output_file("line.html")
p = figure(title="Line plot", x_axis_label='X axis', y_axis_label='Y axis')
p.line(x, y, legend_label="Line", line_width=2)
show(p)
```
5. ggplot
```python
from ggplot import *
df = pd.read_csv('data.csv')
ggplot(aes(x='x', y='y'), data=df) + geom_point()
```
以上是一些常见的 Python 画图库及其代码示例,你可以根据需要选择合适的库来绘制图形。
阅读全文