这是代码:
#/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
f = lambda x: pow(x, 3) / (pow(x, 2) - x - 6)
fig, ax = plt.subplots()
x = np.linspace(-15.0, 15.0, 1000)
plt.axis([x[0], x[-1], -15.0, 15.0])
ax.spines['left'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('center')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ticks = []
for i in range(-15, 16, 5):
ticks.append(i)
ticks.remove(0)
ax.set_xticks(ticks)
ax.set_yticks(ticks)
plt.plot(x, f(x), color='b', linestyle='-', lw=1.5)
plt.plot(x, x + 1.0, color='b', linestyle='--', lw=1.5)
plt.legend([r'$f(x)=\frac{x^3}{x^2-x-6}$', r'$y=x+1$'], loc='lower right')
plt.title('Discontinuous Function')
plt.grid('on')
plt.show()
我想把斧头像一个情节,而不是像一个子情节。我该怎么改变它?感谢。
答案 0 :(得分:0)
为什么不能改变
plt.plot(x, f(x), color='b', linestyle='-', lw=1.5)
plt.plot(x, x + 1.0, color='b', linestyle='--', lw=1.5)
plt.legend([r'$f(x)=\frac{x^3}{x^2-x-6}$', r'$y=x+1$'], loc='lower right')
plt.title('Discontinuous Function')
plt.grid('on')
到
ax.plot(x, f(x), color='b', linestyle='-', lw=1.5)
ax.plot(x, x + 1.0, color='b', linestyle='--', lw=1.5)
ax.legend([r'$f(x)=\frac{x^3}{x^2-x-6}$', r'$y=x+1$'], loc='lower right')
ax.set_title('Discontinuous Function') # notice this one changed to set_title
ax.grid()
plt.show() # keep this one plt.
?否则,我不太确定你的问题是什么。问题究竟在哪里?你有回溯吗?