3

I need to reproduce plots of this type (bifurcation plots) -

bifurcation plot

I tried to follow the example given at change-matplotlib-line-style-mid-graph, but couldn't really work it out. Could someone give a tip?

3
  • What exactly could you not work out? The trick is to draw 4 lines (in your example): 2 solid ones and 2 dashed ones. Commented Nov 24, 2014 at 8:49
  • I don't understand in the link I have given what is the line plt.plot(x[below], y1[below], 'b--') does.. Commented Nov 25, 2014 at 10:55
  • in the example that you linked, below is a vector of bools that is used to select only those values in x and y for which below is True. Commented Nov 25, 2014 at 11:02

1 Answer 1

2

In the following I have put together 4 different examples. They show different things:

  1. The simplest way to recreate the graph in your question. Note, that each line is only defined by two points.
  2. This is what I assume you have: two x and y vectors that define each line (in my example they each have 100 values).
  3. This one is most interesting for you (I guess): The vectors solid1 and solid2 are used to select the values of x and y, that satisfy the conditions.
  4. Just to show you how you can put the spines in the center (since the graph in your question has them centered).

enter image description here

Code:

import numpy as np
import matplotlib.pyplot as plt

plt.figure(figsize=(12,4))

# Example 1
plt.subplot(1,4,1)
line1 = np.array([[-1,0],[0,0]])
line2 = np.array([[0,0],[1,1]])
line3 = np.array([[-1,-1],[0,0]])
line4 = np.array([[0,0],[1,0]])
plt.plot(line1[:,0], line1[:,1], 'b', linewidth=4)
plt.plot(line2[:,0], line2[:,1], 'b', linewidth=4)
plt.plot(line3[:,0], line3[:,1], 'b--', linewidth=4)
plt.plot(line4[:,0], line4[:,1], 'b--', linewidth=4)

# Example 2
plt.subplot(1,4,2)
x1 = np.linspace(-1,1,100)
x2 = np.linspace(-1,1,100)
y1 = x1*0
y2 = x2
plt.plot(x1,y1,'r', linewidth=4)
plt.plot(x2,y2,'g', linewidth=4)

# Example 3
plt.subplot(1,4,3)
#some sort of split condition:
solid1 = x1<0
solid2 = x2>0
#plot each line in two seperate plot calls
plt.plot(x1[solid1], y1[solid1], 'r', linewidth=4)
plt.plot(x1[np.logical_not(solid1)], y1[np.logical_not(solid1)], 'r--', linewidth=4)
plt.plot(x2[solid2], y2[solid2], 'g', linewidth=4)
plt.plot(x2[np.logical_not(solid2)], y2[np.logical_not(solid2)], 'g--', linewidth=4)

# Example 4 
plt.subplot(1,4,4)
# put the spines to the middle
ax = plt.gca()
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')

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.