有时候因为jupyter notebook本身的主题不同,导致画图的时候与图表的颜色冲突,看不清坐标轴,这时候可以通过更换坐标轴风格来解决:
一、更换主题样式
plt.style.available
['Solarize_Light2',
'_classic_test_patch',
'bmh',
'classic',
'dark_background',
'fast',
'fivethirtyeight',
'ggplot',
'grayscale',
'seaborn',
'seaborn-bright',
'seaborn-colorblind',
'seaborn-dark',
'seaborn-dark-palette',
'seaborn-darkgrid',
'seaborn-deep',
'seaborn-muted',
'seaborn-notebook',
'seaborn-paper',
'seaborn-pastel',
'seaborn-poster',
'seaborn-talk',
'seaborn-ticks',
'seaborn-white',
'seaborn-whitegrid',
'tableau-colorblind10']
原始风格:
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['Microsoft YaHei']
plt.title("中国票房2021TOP5")
plt.plot(bo,prices,label='票房与票价')
plt.show()
 更换主题:
plt.style.use('ggplot')

plt.style.use('seaborn')

plt.style.use('classic')
 最终我的效果:
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['Microsoft YaHei']
plt.title("中国票房2021TOP5")
plt.plot(bo,prices,label='票房与票价')
plt.plot(bo,persons,label='票房与人次')
plt.plot(bo,points,label='票房与评价')
plt.legend()
plt.xlabel('票房')
plt.ylabel('行情')
plt.show()

二、线条变换
'r^--' :红色虚线 'g^--' :绿色虚线 'b^--' :蓝色虚线 'g*-' :表示绿色,并且数据标记是一个星号 ^ :表示数据标记为一个向上的三角形
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['Microsoft YaHei']
plt.title("中国票房2021TOP5")
plt.plot(bo,prices,'r^--',label='票房与票价')
plt.plot(bo,persons,label='票房与人次')
plt.plot(bo,points,label='票房与评价')
plt.legend()
plt.xlabel('票房')
plt.ylabel('行情')
plt.show()
  
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['Microsoft YaHei']
plt.title("中国票房2021TOP5")
plt.plot(bo,prices,'r^--',label='票房与票价')
plt.plot(bo,persons,'g*-',label='票房与人次')
plt.plot(bo,points,'bo--',label='票房与评价')
plt.legend()
plt.xlabel('票房')
plt.ylabel('行情')
plt.show()

from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['Microsoft YaHei']
plt.title("中国票房2021TOP5")
plt.plot(bo,prices,'r^--',label='票房与票价')
plt.plot(bo,persons,'g*-',label='票房与人次')
plt.plot(bo,points,color='blue',marker='o',markersize=10,label='票房与评价')
plt.legend()
plt.xlabel('票房')
plt.ylabel('行情')
plt.show()

三、将图表保存成本地图片
plt.savefig("cnbotop5.png")
 
四、添加辅助线
plt.style.use('classic')
from matplotlib import pyplot as plt
plt.rcParams['font.sans-serif']=['Microsoft YaHei']
plt.title("中国票房2021TOP5")
plt.plot(bo,prices,'r^--',label='票房与票价')
plt.plot(bo,persons,'g*-',label='票房与人次')
plt.plot(bo,points,color='blue',marker='o',markersize=10,label='票房与评价')
plt.legend()
plt.xlabel('票房')
plt.ylabel('行情')
plt.show()

plt.grid()

五、调整画图的大小和清晰度
plt.figure(figsize=(16,10),dpi=100)
 这里dpi就相当于清晰度,而figsize就是长度和宽度 
六、使用动漫风格
from matplotlib import pyplot as plt
plt.xkcd()
plt.figure(figsize=(16,10),dpi=100)
plt.rcParams['font.sans-serif']=['Microsoft YaHei']
plt.rcParams.update({'font.family': "Microsoft YaHei"})
plt.title("中国票房2021TOP5")
plt.plot(bo,prices,'r^--',label='票房与票价')
plt.plot(bo,persons,'g*-',label='票房与人次')
plt.plot(bo,points,color='blue',marker='o',markersize=10,label='票房与评价')
plt.legend()
plt.xlabel('票房')
plt.ylabel('行情')
plt.grid()
plt.savefig("cnbotop5_300.png")
plt.show()

|