Which Visualization plot should i use?

Viewed 64

I have data like below and i want to create plot like added picture. I want to visulise this data like sample plot. I searched seaborn and matplotlib libraries but i can't find something like i want.

Also in the sample plot, the intersection point is 0. But i need to change this point. For example the intersection point is 30 for cost and 25 for service.

Can someone help me about that problem?

enter image description here

enter image description here

2 Answers

Here is a simple implementation using matplotlib:

cost=[50,40,30,20,10]
service=[60,30,25,10,20]
fig, (ax) = plt.subplots()

ax.spines['left'].set_position(('data', 25))
ax.spines['bottom'].set_position(('data', 30))
# Eliminate upper and right axes
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')

ax.scatter(cost,service)

Output for above code snippet

You can also refer to: How to draw axis in the middle of the figure?

Per my comment, if it is what you want, you need a Seaborn JointGrid for that kind of stuff. In the example below I just used a histogram distplot for marginals but see the documentation for different kinds of examples.

import seaborn as sns
cost=[50,40,30,20,10,50,50,50,50,50]
service=[60,30,25,10,20,60,30,25,10,20]

grid = sns.JointGrid(cost, service, space=0, height=6, ratio=20)
grid.plot_joint(sns.scatterplot, color="g")
grid.plot_marginals(sns.distplot, kde=False, color="r", bins=10)

grid.fig.axes[0].spines['left'].set_position(('data', 25))
grid.fig.axes[0].spines['bottom'].set_position(('data', 30))
grid.fig.axes[1].spines['bottom'].set_visible(False)
grid.fig.axes[2].spines['left'].set_visible(False)

plt.show(grid)

Here is what is going on with this (I doubled your data to make the histogram a little more interesting). When you create a JointGrid it creates a JointGrid object. Not a fig or axes. A JointPlot object has a fig, and that fig has three axes. The axes[0] is the axis for the main plot, axes1 is the axis for the top marginal plot, and axes[2] is the axis for the right marginal plot. When manipulating the spines for these axes, keep in mind that axes are oriented with the picture. That is, the left spine on axes[2] is the spine that would be the bottom spine if that plot was a regular, horizontal plot.

Related