【发布时间】:2021-03-02 02:05:35
【问题描述】:
我有一个函数可以在给定字典的情况下创建复杂的绘图。现在我有两个字典,我想创建一个多图。直觉会说:
import numpy as np
import matplotlib.pyplot as plt
dict_1={'m':1,'n':0}
dict_2={'m':5,'n':1}
def nice_plot(dict):
x=np.linspace(-5,5)
_,ax=plt.subplots()
return ax.plot(x,dict['m']*x+dict['n'])
fig,ax=plt.subplots(ncols=2)
ax[0]=nice_plot(dict_1)
ax[1]=nice_plot(dict_2)
fig.show()
但它不起作用,它创建一个包含 2 列的空多图,然后绘制两条线。
使用 return plt.plot(x,dict['m']*x+dict['n']) 在第二个轴上绘制两条线。
谢谢!
【问题讨论】:
标签: python matplotlib