New*_*irl 3 python matplotlib pandas
我正在使用该ggplot样式在同一个图上绘制多条线。采用这种风格,线条就变成了全实线。所以能见度不好。如何将每条线更改为不同的样式,例如带有虚线的样式或其他样式?
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')
fig,ax = plt.subplots(figsize=(15,5))
ax.set_title('Loss curve', fontsize=15)
ax.set_ylabel('Loss')
ax.set_xlabel('Epoch')
df1.plot.line(ax=ax,x='epoch',y=["train_loss"])
df2.plot.line(ax=ax,x='epoch',y=["train_loss"])
plt.show()
Run Code Online (Sandbox Code Playgroud)
您可以使用linestyle不同的样式来更改每条线。
这是一个例子:
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')
fig,ax = plt.subplots(figsize=(15,5))
ax.set_title('Loss curve', fontsize=15)
ax.set_ylabel('Loss')
ax.set_xlabel('Epoch')
df1 = pd.DataFrame({'epoch' : [10,20,30,40,50,60],
'train_loss' : [6,5,4,3,2,1]})
df2 = pd.DataFrame({'epoch' : [10,20,30,40,50,60],
'train_loss' : [6.5,5.5,4.5,3.5,2.5,1.5]})
df1.plot.line(ax=ax,x='epoch',y=["train_loss"],
linewidth= 1.5, linestyle='-.')
df2.plot.line(ax=ax,x='epoch',y=["train_loss"], linewidth= 1.5,
linestyle='-')
plt.show()
Run Code Online (Sandbox Code Playgroud)
在plt.plot.line()中,您可以检查更多样式,如实线、虚线、点划线、点线等。
| 归档时间: |
|
| 查看次数: |
7931 次 |
| 最近记录: |