python - making the additional yaxis (parasite axis) visible on my graph

Viewed 163

these are my codes, mostly taken from the example here https://matplotlib.org/2.0.2/examples/axes_grid/demo_parasite_axes2.html

the output graph is shown below


from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
sns.set()
import numpy as np


host = host_subplot(111, axes_class=AA.Axes)
plt.subplots_adjust(left=.15)

par1 = host.twinx()
par2 = host.twinx()

host.tick_params(width=0)
par1.tick_params(width=0)
par2.tick_params(width=0)

offset = -60
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["left"] = new_fixed_axis(loc="left", axes=par2,offset=(offset, 0))
par2.set_ylabel("V3")
par2.axis["left"].toggle(all=True)

xx = np.random.randint(1,10,100)
yy = np.random.randint(-100,10,100)

p1 = host.scatter(xx,yy)

ax = plt.gca()
ax.invert_yaxis()

rolling_period = 3
plt.xlabel('V2')
plt.ylabel('V1')

x1, y1 = [250, 0], [0, 0]
x2, y2 = [0, 0], [-30, 0]
plt.plot(x1,y1,x2,y2,color='black')

plt.xlim([-50, 250])
plt.ylim([0, -30])

plt.tick_params(axis='x',which='both',bottom=False,top=False)
p2, = par1.plot([0, 1, 2], [0, 3, 2], linestyle = 'None', label="V3")


plt.draw()
plt.show()

enter image description here

as you can see if I use seaborn I cant see the axis line for the parasite axis (the additional y axis on the left)

however if I remove the seaborn I do see that, but I do need to use seaborn for visualisation purpose so how do I fix the problem?

the graph without seaborn enter image description here

1 Answers

Seaborn sets axis line colors to white. Just reset it to black by:

par2.axis['left'].line.set_ec((0, 0, 0, 1))

enter image description here

Related