用matplotlib绘制f(x)=0 if x<=1 else (x-1)*(x-1),并明确f(x)=0 when x<=1的部分
Draw f(x)=0 if x<=1 else (x-1)*(x-1) with matplotlib, and make clear the part f(x)=0 when x<=1
我想用matplotlib画图
f(x)=0 if x<=1 else (x-1)*(x-1)
难点在于x<=1时f(x)=0的部分与x轴重叠。我怎样才能让那部分更清楚?谢谢。
您可以使用
控制线条的颜色或粗细
matplotlib.pyplot.plot(x,y,c='green',lw=2)
其中 c
的值是颜色,lw
给出线宽。默认线宽为 1,与轴线融为一体。有关基础知识,请参阅 pyplot tutorial。另一种选择是更改 yaxis 的限制:
matplotlib.pyplot.ylim(-.1,1)
这完全取决于您想要的情节风格。
我想用matplotlib画图
f(x)=0 if x<=1 else (x-1)*(x-1)
难点在于x<=1时f(x)=0的部分与x轴重叠。我怎样才能让那部分更清楚?谢谢。
您可以使用
控制线条的颜色或粗细matplotlib.pyplot.plot(x,y,c='green',lw=2)
其中 c
的值是颜色,lw
给出线宽。默认线宽为 1,与轴线融为一体。有关基础知识,请参阅 pyplot tutorial。另一种选择是更改 yaxis 的限制:
matplotlib.pyplot.ylim(-.1,1)
这完全取决于您想要的情节风格。