Query about streamplot

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Query about streamplot

Dhirendra Kumar
Hii Folks

I have an array with dimension (plev: 7, lat: 81). I was trying to draw streamline plot for Omega and V wind [Hadley cell].  I am facing some error with plt.streamplot as it says that both the dimension should be of equal size (i.e. N * N ). Is there any other way to create a streamline plot for the data having unequal values along both the dimensions?

I seek help of the community in this regard.

I hope I framed my question correctly.  Please let me know if I need to clarify more details.

Thank you

--
========================================
Dhirendra Kumar
PhD Student
School of Environmental Sciences, JNU
New Delhi (India)
Contact: +91 9910778043
Alternate email: [hidden email]
=========================================

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Query about streamplot

vincent.adrien@gmail.com
Hi Kumar,

Could provided a snippet with a (standalone) minimal working example of what you have tried ?

AFAICT, looking at https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.streamplot.html it does not look like X and Y arrays of coordinates have to be of equal length (but the velocity arrays U and V should have relevant dimensions relative to X and Y).

Best regards,
Adrien



On April 16, 2019 11:05:01 PM GMT+02:00, Dhirendra Kumar <[hidden email]> wrote:

>Hii Folks
>
>I have an array with dimension (plev: 7, lat: 81). I was trying to draw
>streamline plot for Omega and V wind [Hadley cell].  I am facing some
>error
>with* plt.streamplot* as it says that both the dimension should be of
>equal
>size (i.e. N * N ). Is there any other way to create a streamline plot
>for
>the data having unequal values along both the dimensions?
>
>I seek help of the community in this regard.
>
>I hope I framed my question correctly.  Please let me know if I need to
>clarify more details.
>
>Thank you

--
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Query about streamplot

vincent.adrien@gmail.com
Kumar,

FWIW, based on the [streamplot
example](https://matplotlib.org/gallery/images_contours_and_fields/plot_streamplot.html)
in the gallery, the following snippet seems to be working just fine
(with Matplotlib 3.0.1) “even though” the amount of X and Y coordinate
values is (Nx, Ny) = (100, 50).

```python
import numpy as np
import matplotlib.pyplot as plt

# Dummy data
w = 3
Nx, Ny = 100, 50
Y, X = np.mgrid[-w:w:50j, -w:w:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2

fig, ax = plt.subplots()

ax.streamplot(X, Y, U, V)
ax.set_title(f"{Nx/Ny:g}× more points along X than Y")
```

Best,
Adrien

Le 17/04/2019 à 08:14, Adrien VINCENT a écrit :

> Hi Kumar,
>
> Could provided a snippet with a (standalone) minimal working example of what you have tried ?
>
> AFAICT, looking at https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.streamplot.html it does not look like X and Y arrays of coordinates have to be of equal length (but the velocity arrays U and V should have relevant dimensions relative to X and Y).
>
> Best regards,
> Adrien
>
>
>
> On April 16, 2019 11:05:01 PM GMT+02:00, Dhirendra Kumar <[hidden email]> wrote:
>> Hii Folks
>>
>> I have an array with dimension (plev: 7, lat: 81). I was trying to draw
>> streamline plot for Omega and V wind [Hadley cell].  I am facing some
>> error
>> with* plt.streamplot* as it says that both the dimension should be of
>> equal
>> size (i.e. N * N ). Is there any other way to create a streamline plot
>> for
>> the data having unequal values along both the dimensions?
>>
>> I seek help of the community in this regard.
>>
>> I hope I framed my question correctly.  Please let me know if I need to
>> clarify more details.
>>
>> Thank you
>

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

streamplot_example_for_kumar.png (115K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Query about streamplot

Dhirendra Kumar
Hii Adrien

Thanks for the reply. I have tried your example and could replicate it. But in case of my script I have two variables:

V and Omega having sizes:
([('plev', 12), ('lat', 81)]))
([('plev', 12), ('lat', 81)]))

Plev has to be plotted on y axis and lat has to be plotted on x axis. 

I am using following lines to create the plot:

plt.subplot(331)
plt.contourf(CC_W_CON11,cmap='RdBu')
plt.streamplot(X, Y, Omega,  V)

This gives me an error as:

  File "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2951, in streamplot
    if data is not None else {}))
  File "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/__init__.py", line 1810, in inner
    return func(ax, *args, **kwargs)
  File "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4882, in streamplot
    integration_direction=integration_direction)
  File "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/streamplot.py", line 79, in streamplot
    grid = Grid(x, y)
  File "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/streamplot.py", line 311, in __init__
    raise ValueError("The rows of 'x' must be equal")
ValueError: The rows of 'x' must be equal

Could you please look if there is any mistake ??

Thanks


On Wed, Apr 17, 2019 at 1:27 PM [hidden email] <[hidden email]> wrote:
Kumar,

FWIW, based on the [streamplot
example](https://matplotlib.org/gallery/images_contours_and_fields/plot_streamplot.html)
in the gallery, the following snippet seems to be working just fine
(with Matplotlib 3.0.1) “even though” the amount of X and Y coordinate
values is (Nx, Ny) = (100, 50).

```python
import numpy as np
import matplotlib.pyplot as plt

# Dummy data
w = 3
Nx, Ny = 100, 50
Y, X = np.mgrid[-w:w:50j, -w:w:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2

fig, ax = plt.subplots()

ax.streamplot(X, Y, U, V)
ax.set_title(f"{Nx/Ny:g}× more points along X than Y")
```

Best,
Adrien

Le 17/04/2019 à 08:14, Adrien VINCENT a écrit :
> Hi Kumar,
>
> Could provided a snippet with a (standalone) minimal working example of what you have tried ?
>
> AFAICT, looking at https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.streamplot.html it does not look like X and Y arrays of coordinates have to be of equal length (but the velocity arrays U and V should have relevant dimensions relative to X and Y).
>
> Best regards,
> Adrien
>
>
>
> On April 16, 2019 11:05:01 PM GMT+02:00, Dhirendra Kumar <[hidden email]> wrote:
>> Hii Folks
>>
>> I have an array with dimension (plev: 7, lat: 81). I was trying to draw
>> streamline plot for Omega and V wind [Hadley cell].  I am facing some
>> error
>> with* plt.streamplot* as it says that both the dimension should be of
>> equal
>> size (i.e. N * N ). Is there any other way to create a streamline plot
>> for
>> the data having unequal values along both the dimensions?
>>
>> I seek help of the community in this regard.
>>
>> I hope I framed my question correctly.  Please let me know if I need to
>> clarify more details.
>>
>> Thank you
>



--
========================================
Dhirendra Kumar
PhD Student
School of Environmental Sciences, JNU
New Delhi (India)
Contact: +91 9910778043
Alternate email: [hidden email]
=========================================

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Query about streamplot

vincent.adrien@gmail.com
Kumar,

As far as I understand it, it looks like your issue may be due to X (and
possibly Y) being 2d-array. If V and Omega are arrays with shape **(Ny,
Nx)**, then X and Y should be **1d-arrays** with Nx and Ny elements
respectively. For simplicity sake (I guess), there is actually a special
(not very well documented) case if X and Y are 2d-arrays :
- each row of X has to be the same;
- each column in Y has to be same.

The error that you saw suggest that the rows in your array X differ from
one another.

Adrien

Le 17/04/2019 à 11:55, Dhirendra Kumar a écrit :

> Hii Adrien
>
> Thanks for the reply. I have tried your example and could replicate it.
> But in case of my script I have two variables:
>
> *V* and *Omega* having sizes:
> ([('plev', 12), ('lat', 81)]))
> ([('plev', 12), ('lat', 81)]))
>
> Plev has to be plotted on y axis and lat has to be plotted on x axis. 
>
> I am using following lines to create the plot:
>
> plt.subplot(331)
> plt.contourf(CC_W_CON11,cmap='RdBu')
> plt.streamplot(X, Y, Omega,  V)
>
> This gives me an error as:
>
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/pyplot.py",
> line 2951, in streamplot
>     if data is not None else {}))
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/__init__.py",
> line 1810, in inner
>     return func(ax, *args, **kwargs)
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/axes/_axes.py",
> line 4882, in streamplot
>     integration_direction=integration_direction)
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/streamplot.py",
> line 79, in streamplot
>     grid = Grid(x, y)
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/streamplot.py",
> line 311, in __init__
>     raise ValueError("The rows of 'x' must be equal")
> *ValueError: The rows of 'x' must be equal*
> *
> *
> Could you please look if there is any mistake ??
>
> Thanks
>
>
> On Wed, Apr 17, 2019 at 1:27 PM [hidden email]
> <mailto:[hidden email]> <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Kumar,
>
>     FWIW, based on the [streamplot
>     example](https://matplotlib.org/gallery/images_contours_and_fields/plot_streamplot.html)
>     in the gallery, the following snippet seems to be working just fine
>     (with Matplotlib 3.0.1) “even though” the amount of X and Y coordinate
>     values is (Nx, Ny) = (100, 50).
>
>     ```python
>     import numpy as np
>     import matplotlib.pyplot as plt
>
>     # Dummy data
>     w = 3
>     Nx, Ny = 100, 50
>     Y, X = np.mgrid[-w:w:50j, -w:w:100j]
>     U = -1 - X**2 + Y
>     V = 1 + X - Y**2
>
>     fig, ax = plt.subplots()
>
>     ax.streamplot(X, Y, U, V)
>     ax.set_title(f"{Nx/Ny:g}× more points along X than Y")
>     ```
>
>     Best,
>     Adrien
>
>     Le 17/04/2019 à 08:14, Adrien VINCENT a écrit :
>     > Hi Kumar,
>     >
>     > Could provided a snippet with a (standalone) minimal working
>     example of what you have tried ?
>     >
>     > AFAICT, looking at
>     https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.streamplot.html
>     it does not look like X and Y arrays of coordinates have to be of
>     equal length (but the velocity arrays U and V should have relevant
>     dimensions relative to X and Y).
>     >
>     > Best regards,
>     > Adrien
>     >
>     >
>     >
>     > On April 16, 2019 11:05:01 PM GMT+02:00, Dhirendra Kumar
>     <[hidden email] <mailto:[hidden email]>> wrote:
>     >> Hii Folks
>     >>
>     >> I have an array with dimension (plev: 7, lat: 81). I was trying
>     to draw
>     >> streamline plot for Omega and V wind [Hadley cell].  I am facing some
>     >> error
>     >> with* plt.streamplot* as it says that both the dimension should be of
>     >> equal
>     >> size (i.e. N * N ). Is there any other way to create a streamline
>     plot
>     >> for
>     >> the data having unequal values along both the dimensions?
>     >>
>     >> I seek help of the community in this regard.
>     >>
>     >> I hope I framed my question correctly.  Please let me know if I
>     need to
>     >> clarify more details.
>     >>
>     >> Thank you
>     >
>
>
>
> --
> ========================================
> Dhirendra Kumar
> PhD Student
> School of Environmental Sciences, JNU
> New Delhi (India)
> Contact: +91 9910778043
> Alternate email: [hidden email]
> <mailto:[hidden email]>
> =========================================

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Query about streamplot

Dhirendra Kumar
Hii Adrien

I guess I have found the problem but don't know how to go about it. The documentation here (https://matplotlib.org/api/_as_gen/matplotlib.pyplot.streamplot.html) says that  x and y should be:

xy : 1d arrays
an evenly spaced grid.
but in my case although I have the same shape of the V and Omega values, it is unevenly distributed as a grid. The plev values are: [1000.  925.  850.  700.  600.  500.  400.  300.  250.  200.  150.  100.] while x varies from 0-40 N at an interval of 0.5. So apparently it produces an unevely distributed gridspace in lat-plev (xy).
Please let me know what you think about this.
Thanks
Dhirendra

On Wed, Apr 17, 2019 at 7:51 PM [hidden email] <[hidden email]> wrote:
Kumar,

As far as I understand it, it looks like your issue may be due to X (and
possibly Y) being 2d-array. If V and Omega are arrays with shape **(Ny,
Nx)**, then X and Y should be **1d-arrays** with Nx and Ny elements
respectively. For simplicity sake (I guess), there is actually a special
(not very well documented) case if X and Y are 2d-arrays :
- each row of X has to be the same;
- each column in Y has to be same.

The error that you saw suggest that the rows in your array X differ from
one another.

Adrien

Le 17/04/2019 à 11:55, Dhirendra Kumar a écrit :
> Hii Adrien
>
> Thanks for the reply. I have tried your example and could replicate it.
> But in case of my script I have two variables:
>
> *V* and *Omega* having sizes:
> ([('plev', 12), ('lat', 81)]))
> ([('plev', 12), ('lat', 81)]))
>
> Plev has to be plotted on y axis and lat has to be plotted on x axis. 
>
> I am using following lines to create the plot:
>
> plt.subplot(331)
> plt.contourf(CC_W_CON11,cmap='RdBu')
> plt.streamplot(X, Y, Omega,  V)
>
> This gives me an error as:
>
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/pyplot.py",
> line 2951, in streamplot
>     if data is not None else {}))
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/__init__.py",
> line 1810, in inner
>     return func(ax, *args, **kwargs)
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/axes/_axes.py",
> line 4882, in streamplot
>     integration_direction=integration_direction)
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/streamplot.py",
> line 79, in streamplot
>     grid = Grid(x, y)
>   File
> "/opt/apps/ANACONDA/lib/python3.7/site-packages/matplotlib/streamplot.py",
> line 311, in __init__
>     raise ValueError("The rows of 'x' must be equal")
> *ValueError: The rows of 'x' must be equal*
> *
> *
> Could you please look if there is any mistake ??
>
> Thanks
>
>
> On Wed, Apr 17, 2019 at 1:27 PM [hidden email]
> <mailto:[hidden email]> <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Kumar,
>
>     FWIW, based on the [streamplot
>     example](https://matplotlib.org/gallery/images_contours_and_fields/plot_streamplot.html)
>     in the gallery, the following snippet seems to be working just fine
>     (with Matplotlib 3.0.1) “even though” the amount of X and Y coordinate
>     values is (Nx, Ny) = (100, 50).
>
>     ```python
>     import numpy as np
>     import matplotlib.pyplot as plt
>
>     # Dummy data
>     w = 3
>     Nx, Ny = 100, 50
>     Y, X = np.mgrid[-w:w:50j, -w:w:100j]
>     U = -1 - X**2 + Y
>     V = 1 + X - Y**2
>
>     fig, ax = plt.subplots()
>
>     ax.streamplot(X, Y, U, V)
>     ax.set_title(f"{Nx/Ny:g}× more points along X than Y")
>     ```
>
>     Best,
>     Adrien
>
>     Le 17/04/2019 à 08:14, Adrien VINCENT a écrit :
>     > Hi Kumar,
>     >
>     > Could provided a snippet with a (standalone) minimal working
>     example of what you have tried ?
>     >
>     > AFAICT, looking at
>     https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.streamplot.html
>     it does not look like X and Y arrays of coordinates have to be of
>     equal length (but the velocity arrays U and V should have relevant
>     dimensions relative to X and Y).
>     >
>     > Best regards,
>     > Adrien
>     >
>     >
>     >
>     > On April 16, 2019 11:05:01 PM GMT+02:00, Dhirendra Kumar
>     <[hidden email] <mailto:[hidden email]>> wrote:
>     >> Hii Folks
>     >>
>     >> I have an array with dimension (plev: 7, lat: 81). I was trying
>     to draw
>     >> streamline plot for Omega and V wind [Hadley cell].  I am facing some
>     >> error
>     >> with* plt.streamplot* as it says that both the dimension should be of
>     >> equal
>     >> size (i.e. N * N ). Is there any other way to create a streamline
>     plot
>     >> for
>     >> the data having unequal values along both the dimensions?
>     >>
>     >> I seek help of the community in this regard.
>     >>
>     >> I hope I framed my question correctly.  Please let me know if I
>     need to
>     >> clarify more details.
>     >>
>     >> Thank you
>     >
>
>
>
> --
> ========================================
> Dhirendra Kumar
> PhD Student
> School of Environmental Sciences, JNU
> New Delhi (India)
> Contact: +91 9910778043
> Alternate email: [hidden email]
> <mailto:[hidden email]>
> =========================================



--
========================================
Dhirendra Kumar
PhD Student
School of Environmental Sciences, JNU
New Delhi (India)
Contact: +91 9910778043
Alternate email: [hidden email]
=========================================

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users