How can I make streamplot not have blank spaces?

Viewed 89

I'm trying to draw a vector field of a dynamic system with. I'm using the streamplot method from matplotlib.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr  9 09:14:26 2021

@author: samuel
"""

import numpy as np
# from numpy.linalg import eig #para calcular los autovalores y autovectores
from scipy.integrate import odeint #Para resolver el sistema de ecuaciones diferenciales
import matplotlib.pyplot as plt #Para graficar
# import matplotlib.cm as cm
import os #Para acceder al directorio y cambiar archivos
# from pathlib import Path #Para encontrar el path del directorio
# import imageio #Para crear el GIF


#For the user
R_L_tiempo = False 
R_L_punto = True
Nulclinas = True

#Parametros
a,c =  0.1, 0.033 #Parametros del problema
tiempo = np.linspace(0, 100, 10000) #Tiempo de observacion

# a=c+2*np.sqrt(b)
b=float(input('b=' ))

#Condiciones iniciales
condiciones_iniciales = [10,10] #v(t=0) y w(t=0)

#Resolving the differential equation system
#variables[0] is v(t) and variables[1] is w(t)
def sistema_de_ecuaciones(variables, t):
    return [variables[0]*(a-variables[0])*(variables[0]-1)-variables[1], b*variables[0]-c*variables[1]]

soluciones = odeint(sistema_de_ecuaciones, condiciones_iniciales, tiempo) #Sacamos R(t) y L(t)

v = soluciones[:,0] #v(t)
w = soluciones[:,1] #w(t)

#Plotting results
if(R_L_tiempo):
    fig, ax = plt.subplots(figsize=(12.80,7.20))

    plt.plot(tiempo, v, "-", label="v")
    plt.plot(tiempo, w, "-", label="w")
    plt.xlabel("Tiempo")
    plt.ylabel("Cantidad de amor")

    plt.plot([], [], " ", label="$\dot{R} = R + L$")
    plt.plot([], [], " ", label="$\dot{L} = -3R + L$")

    plt.legend(loc="best")

    plt.axhline(y=0, color='k')
    plt.axvline(x=0, color='k')

    plt.tight_layout()

    plt.show()

if(R_L_punto):
    fig, ax = plt.subplots(figsize=(12.80,7.50))

    # plt.plot(v, w, "-", color='g', label="Diagrama $R-L$")
    # plt.plot(-v, -w, "-", color='g') #La pongo una segunda vez para que aparezca en los dos lados del eje de abscisas
    plt.xlabel("v", fontsize=14)
    plt.ylabel("w", fontsize=14)

    if(Nulclinas):
        #Las pongo dos veces para que aparezcan en los dos lados del eje de abscisas
        L_W=3 #Linewidthfrac12
        plt.plot(v, v*(a-v)*(v-1), "-", color='g', linewidth=L_W, label="$\dot{v}=0$")
        plt.plot(v, b/c*v, "-", color='r', linewidth=L_W, label="$\dot{w}=0$")
        plt.plot(-v, -v*(a+v)*(-v-1), "-", color='g', linewidth=L_W)
        plt.plot(-v, -b/c*v, "-", color='r', linewidth=L_W)


    #Velocity field
    xabs=5
    yabs=5
    min_x, max_x, min_y, max_y = -xabs,xabs, -yabs, yabs

    #Generate graph
    x,y = np.meshgrid(np.linspace(min_x, max_x, 100),np.linspace(min_y, max_y, 100))

    #Las velocidades en el espacio (X,Y)
    v_punto = x*(a-x)*(x-1)-y
    w_punto = b*x-c*y

    ax.streamplot(x, y, v_punto, w_punto, density=1.8, color='b', linewidth=2, cmap='cool') #Para cambiar color: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html
    #ax.quiver(x, y, R_punto, L_punto, linewidth=1) #[To see the velocities with arrows]

    # plt.plot([], [], "-", color='r', label="Nulclinas")
    # plt.plot([], [], "-", color='b', label="Trayectorias")
    plt.xlim(min_x, max_x)
    plt.ylim(min_y, max_y)

    plt.axhline(y=0, color='k')
    plt.axvline(x=0, color='k')

    # plt.tight_layout()
    ax.set_title('a='+ str(a) +', b=' +str(b) +', c=' +str(c), fontsize=20)
    plt.grid()
    plt.legend(loc="lower left",  fontsize=14)

    #For saving the image
    path=os.getcwd()
    plt.savefig(os.path.abspath(os.path.join(path, os.pardir))+"/img/resultado_2b.png")
    #Para ver la imagen
    #plt.show()

My problem is that I get the image with undisered blank space.

Here the image

I'm guessing this has to do with the density parameter in streamplot. How can I allow to the function to draw the lines in those places where they agglutinate?

PS: I'm new to python and will gratefully take any tips you have in improving the code above :D

0 Answers
Related