Hi Sushil,

I think so — here is an example of 3D streamline with mplot3d: http://yt-project.org/docs/dev/cookbook/complex_plots.html#plotting-streamlines, and you could modify it for quiver plotting by adopting this example: http://matplotlib.org/examples/mplot3d/quiver3d_demo.html

Best wishes,
--
Suoqing JI
Ph.D Candidate
Department of Physics
University of California, Santa Barbara

On Mar 16, 2016, at 1:56 PM, Sushilkumar <sushil.sush19us@gmail.com> wrote:

Dear Suoqing Ji and yt:

Thank you for your help. It worked

In addition, does yt support 3D quiver plots?

If not what is the equivalent for visualizing 3d magnetic fields.


On Wed, Mar 16, 2016 at 2:49 PM, <yt-users-request@lists.spacepope.org> wrote:
Send yt-users mailing list submissions to
        yt-users@lists.spacepope.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
or, via email, send a message with subject or body 'help' to
        yt-users-request@lists.spacepope.org

You can reach the person managing the list at
        yt-users-owner@lists.spacepope.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of yt-users digest..."


Today's Topics:

   1. Error while using annotate magnetic fields (Sushilkumar)
   2. Re: Error while using annotate magnetic fields (Suoqing Ji)


----------------------------------------------------------------------

Message: 1
Date: Wed, 16 Mar 2016 14:16:37 -0500
From: Sushilkumar <sushil.sush19us@gmail.com>
To: Discussion of the yt analysis package
        <yt-users@lists.spacepope.org>
Subject: [yt-users] Error while using annotate magnetic fields
Message-ID:
        <CAKARaKWgFBsh7qZj8Px+OS0-tDUOuKcv2MrWyJh3NaGtj06-9g@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Dear yt:

I am trying to plot magnetic field lines using the annotate magnetic field
call back from the link http://yt-project.org/doc/visualizing/callbacks.html
link.

However, after running the script it gives the error below. A google drive
link to my script (yt_numpy_load_B.py) is also given below. When I use
quiver annotate it works fine but issue comes when I am using
slc.annotate_magnetic_field().
Quiver plots are also available on the drive link.

Thanks in advance

===============
Google drive link
https://drive.google.com/open?id=0B4g8shg4DL7oak5PLWVVdG5UMHc
===============

===============
Error while running the script

  File "yt_numpy_load_B.py", line 47, in <module>
    slc.save()
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_container.py",
line 77, in newfunc
    args[0]._setup_plots()
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py",
line 980, in _setup_plots
    self.run_callbacks()
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py",
line 1033, in run_callbacks
    sys.exc_info()[2])
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py",
line 1029, in run_callbacks
    callback(cbw)
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py",
line 316, in __call__
    return qcb(plot)
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py",
line 357, in __call__
    fv_x = plot.data[self.field_x]
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/data_containers.py",
line 246, in __getitem__
    f = self._determine_fields([key])[0]
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/data_containers.py",
line 518, in _determine_fields
    finfo = self.ds._get_field_info("unknown", fname)
  File
"/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/static_output.py",
line 543, in _get_field_info
    raise YTFieldNotFound((ftype, fname), self)
yt.utilities.exceptions.YTPlotCallbackError: annotate_magnetic_field
callback failed with the following error: Could not find field '('all',
'magnetic_field_x')' in UniformGridData.
===============




On Wed, Mar 16, 2016 at 12:52 PM, <yt-users-request@lists.spacepope.org>
wrote:

> Send yt-users mailing list submissions to
>         yt-users@lists.spacepope.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
> or, via email, send a message with subject or body 'help' to
>         yt-users-request@lists.spacepope.org
>
> You can reach the person managing the list at
>         yt-users-owner@lists.spacepope.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of yt-users digest..."
>
>
> Today's Topics:
>
>    1. Re: Making averaged line plot. (Suoqing Ji)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 15 Mar 2016 15:23:43 -0700
> From: Suoqing Ji <suoqing@physics.ucsb.edu>
> To: Discussion of the yt analysis package
>         <yt-users@lists.spacepope.org>
> Subject: Re: [yt-users] Making averaged line plot.
> Message-ID: <70E5BA6C-7798-45F2-AE83-21233252E109@physics.ucsb.edu>
> Content-Type: text/plain; charset="utf-8"
>
> Hi Yuxiao,
>
> If you would like to start from your current code, the most
> straightforward way is to write a loop to smooth over a certain distance by
> each step, which also works for AMR data:
>
> smooth_len = 100 # smoothing length of 100 kpc
> SmoothedBMag = np.copy(ray[?ScaledBMag?]) # store the smoothed array
> bin_num = np.ceiling((ray[?x?].max() - ray[?x?].min()) / smooth_len) #
> make bins every 100 kpc
>
> for step in range(bin_num):
>     mask1 = (ray[?x?] >= ray[?x?].min() + step * smooth_len)
>     mask2 = (ray[?x?] < ray[?x?].min() + (step + 1) * smooth_len)
>     mask = np.logical_and(mask1, mask2) # mask the cells within a certain
> length of 100 kpc
>     SmoothedBMag[mask] = np.mean(ray[?ScaledBMag?][mask]) # take the
> average and save
>
> After that the array ?SmoothedBMag? is the smoothed one.
>
> However, an easier way is to use the the 1D ProfilePlot function (
> http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots <
> http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots>),
> and in this case you could do something like:
>
> plot = ProfilePlot(pf.h.all_data(), ?x?, [?ScaledBMag?], n_bins=bin_num)
>
> Note that this will do the average over entire y-z plane for each x bins,
> which is different from averaging only an array of a ray object (so maybe
> it?s not what you want). If you really want the data within a thin slit
> only, you could define a region object pf.h.region() and do ProfilePlot. I
> think it?s also doable to use the function ?load_uniform_grid? to create a
> 1D dataset from the arrays in ray object and pass it to ProfilePlot.
>
> Best wishes,
> --
> Suoqing JI
> Ph.D Candidate
> Department of Physics
> University of California, Santa Barbara
> http://web.physics.ucsb.edu/~suoqing
>
> > On Mar 14, 2016, at 10:57 PM, Yuxiao Dai <yuxiao.dai@nyu.edu> wrote:
> >
> > Dear all,
> >
> > I have a line plot of some parameter along an axis as a function of
> distance. Now I would like to get another line plot of the same parameter
> but averaged over a certain distance (say 100 kpc, the plot below is
> supposed to be flat after this). I've been searching the document for some
> time but haven't found a method. Is there a simple way to do this?
> >
> > I would very much appreciate it if anyone could help me on this.
> >
> >
> > ===================================
> > import ...
> >
> > def _ScaledBMag(field, data):
> >
> >     return ...
> >
> >
> >
> > ....
> >
> > pf = load(filename)
> >
> >     add_field("ScaledBMag", function=_ScaledBMag)
> >
> >
> >
> >     c = pf.h.find_max('ScaledBMag')[1]
> >
> >     ax = 0
> >
> >     ray = pf.h.ortho_ray(ax, (c[1], c[2]))
> >
> >
> >     P.subplot(211)
> >
> >     P.semilogy(ray['x'], ray['ScaledBMag'])
> >
> >     P.xlabel('x')
> >
> >     P.ylabel('ScaledBMag')
> >
> >     print "works"
> >
> >     P.savefig("ScaledBMag_lineplot.png")
> >
> >
> > <image.png>
> >
> > ===================================
> > I'm using yt
> >
> > Version = 2.6.1
> >
> >
> > Changeset = c994959ed3be
> >
> > ===================================
> >
> >
> >
> >
> >
> > Regards,
> >
> > Dai
> >
> > _______________________________________________
> > yt-users mailing list
> > yt-users@lists.spacepope.org
> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160315/8afc239c/attachment.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> yt-users mailing list
> yt-users@lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
> ------------------------------
>
> End of yt-users Digest, Vol 97, Issue 19
> ****************************************
>



--
*SK2*

*"**Claiming that something can move faster than light is a good
conversation-stopper in physics. People edge away from you in cocktail
parties; friends never return phone calls. You just don?t mess with Albert
Einstein.**"*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160316/9ea3afb5/attachment-0001.htm>

------------------------------

Message: 2
Date: Wed, 16 Mar 2016 12:49:09 -0700
From: Suoqing Ji <suoqing@physics.ucsb.edu>
To: Discussion of the yt analysis package
        <yt-users@lists.spacepope.org>
Subject: Re: [yt-users] Error while using annotate magnetic fields
Message-ID: <9CA99B80-FF30-44F0-B8C8-74EBC0A4E3CA@physics.ucsb.edu>
Content-Type: text/plain; charset="utf-8"

Hi Sushil,

I think what you need to do is to assign the correct field name when loading the data. In your script, you have:

data = dict(field1 = field1,
            field2 = field2,
            field3 = field3)

which could be, say,

data = dict(magnetic_field_x = field1,
            magnetic_field_y = field2,
            magnetic_field_z = field3)

since annotate_magnetic_field will directly refer to these field names (in fact it's a specialized version of annotate_quiver).

Best wishes,
--
Suoqing JI
Ph.D Candidate
Department of Physics
University of California, Santa Barbara
http://web.physics.ucsb.edu/~suoqing

> On Mar 16, 2016, at 12:16 PM, Sushilkumar <sushil.sush19us@gmail.com> wrote:
>
> Dear yt:
>
> I am trying to plot magnetic field lines using the annotate magnetic field call back from the link http://yt-project.org/doc/visualizing/callbacks.html <http://yt-project.org/doc/visualizing/callbacks.html> link.
>
> However, after running the script it gives the error below. A google drive link to my script (yt_numpy_load_B.py) is also given below. When I use quiver annotate it works fine but issue comes when I am using slc.annotate_magnetic_field().
> Quiver plots are also available on the drive link.
>
> Thanks in advance
>
> ===============
> Google drive link
> https://drive.google.com/open?id=0B4g8shg4DL7oak5PLWVVdG5UMHc <https://drive.google.com/open?id=0B4g8shg4DL7oak5PLWVVdG5UMHc>
> ===============
>
> ===============
> Error while running the script
>
>   File "yt_numpy_load_B.py", line 47, in <module>
>     slc.save()
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_container.py", line 77, in newfunc
>     args[0]._setup_plots()
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 980, in _setup_plots
>     self.run_callbacks()
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1033, in run_callbacks
>     sys.exc_info()[2])
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_window.py", line 1029, in run_callbacks
>     callback(cbw)
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py", line 316, in __call__
>     return qcb(plot)
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/visualization/plot_modifications.py", line 357, in __call__
>     fv_x = plot.data[self.field_x]
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/data_containers.py", line 246, in __getitem__
>     f = self._determine_fields([key])[0]
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/data_containers.py", line 518, in _determine_fields
>     finfo = self.ds._get_field_info("unknown", fname)
>   File "/state/partition1/anaconda/lib/python2.7/site-packages/yt/data_objects/static_output.py", line 543, in _get_field_info
>     raise YTFieldNotFound((ftype, fname), self)
> yt.utilities.exceptions.YTPlotCallbackError: annotate_magnetic_field callback failed with the following error: Could not find field '('all', 'magnetic_field_x')' in UniformGridData.
> ===============
>
>
>
>
> On Wed, Mar 16, 2016 at 12:52 PM, <yt-users-request@lists.spacepope.org <mailto:yt-users-request@lists.spacepope.org>> wrote:
> Send yt-users mailing list submissions to
>         yt-users@lists.spacepope.org <mailto:yt-users@lists.spacepope.org>
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org <http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org>
> or, via email, send a message with subject or body 'help' to
>         yt-users-request@lists.spacepope.org <mailto:yt-users-request@lists.spacepope.org>
>
> You can reach the person managing the list at
>         yt-users-owner@lists.spacepope.org <mailto:yt-users-owner@lists.spacepope.org>
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of yt-users digest..."
>
>
> Today's Topics:
>
>    1. Re: Making averaged line plot. (Suoqing Ji)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 15 Mar 2016 15:23:43 -0700
> From: Suoqing Ji <suoqing@physics.ucsb.edu <mailto:suoqing@physics.ucsb.edu>>
> To: Discussion of the yt analysis package
>         <yt-users@lists.spacepope.org <mailto:yt-users@lists.spacepope.org>>
> Subject: Re: [yt-users] Making averaged line plot.
> Message-ID: <70E5BA6C-7798-45F2-AE83-21233252E109@physics.ucsb.edu <mailto:70E5BA6C-7798-45F2-AE83-21233252E109@physics.ucsb.edu>>
> Content-Type: text/plain; charset="utf-8"
>
> Hi Yuxiao,
>
> If you would like to start from your current code, the most straightforward way is to write a loop to smooth over a certain distance by each step, which also works for AMR data:
>
> smooth_len = 100 # smoothing length of 100 kpc
> SmoothedBMag = np.copy(ray[?ScaledBMag?]) # store the smoothed array
> bin_num = np.ceiling((ray[?x?].max() - ray[?x?].min()) / smooth_len) # make bins every 100 kpc
>
> for step in range(bin_num):
>     mask1 = (ray[?x?] >= ray[?x?].min() + step * smooth_len)
>     mask2 = (ray[?x?] < ray[?x?].min() + (step + 1) * smooth_len)
>     mask = np.logical_and(mask1, mask2) # mask the cells within a certain length of 100 kpc
>     SmoothedBMag[mask] = np.mean(ray[?ScaledBMag?][mask]) # take the average and save
>
> After that the array ?SmoothedBMag? is the smoothed one.
>
> However, an easier way is to use the the 1D ProfilePlot function (http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots <http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots> <http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots <http://yt-project.org/docs/2.6/visualizing/plots.html#d-profile-plots>>), and in this case you could do something like:
>
> plot = ProfilePlot(pf.h.all_data(), ?x?, [?ScaledBMag?], n_bins=bin_num)
>
> Note that this will do the average over entire y-z plane for each x bins, which is different from averaging only an array of a ray object (so maybe it?s not what you want). If you really want the data within a thin slit only, you could define a region object pf.h.region() and do ProfilePlot. I think it?s also doable to use the function ?load_uniform_grid? to create a 1D dataset from the arrays in ray object and pass it to ProfilePlot.
>
> Best wishes,
> --
> Suoqing JI
> Ph.D Candidate
> Department of Physics
> University of California, Santa Barbara
> http://web.physics.ucsb.edu/~suoqing <http://web.physics.ucsb.edu/~suoqing>
>
> > On Mar 14, 2016, at 10:57 PM, Yuxiao Dai <yuxiao.dai@nyu.edu <mailto:yuxiao.dai@nyu.edu>> wrote:
> >
> > Dear all,
> >
> > I have a line plot of some parameter along an axis as a function of distance. Now I would like to get another line plot of the same parameter but averaged over a certain distance (say 100 kpc, the plot below is supposed to be flat after this). I've been searching the document for some time but haven't found a method. Is there a simple way to do this?
> >
> > I would very much appreciate it if anyone could help me on this.
> >
> >
> > ===================================
> > import ...
> >
> > def _ScaledBMag(field, data):
> >
> >     return ...
> >
> >
> >
> > ....
> >
> > pf = load(filename)
> >
> >     add_field("ScaledBMag", function=_ScaledBMag)
> >
> >
> >
> >     c = pf.h.find_max('ScaledBMag')[1]
> >
> >     ax = 0
> >
> >     ray = pf.h.ortho_ray(ax, (c[1], c[2]))
> >
> >
> >     P.subplot(211)
> >
> >     P.semilogy(ray['x'], ray['ScaledBMag'])
> >
> >     P.xlabel('x')
> >
> >     P.ylabel('ScaledBMag')
> >
> >     print "works"
> >
> >     P.savefig("ScaledBMag_lineplot.png")
> >
> >
> > <image.png>
> >
> > ===================================
> > I'm using yt
> >
> > Version = 2.6.1
> >
> >
> > Changeset = c994959ed3be
> >
> > ===================================
> >
> >
> >
> >
> >
> > Regards,
> >
> > Dai
> >
> > _______________________________________________
> > yt-users mailing list
> > yt-users@lists.spacepope.org <mailto:yt-users@lists.spacepope.org>
> > http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org <http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160315/8afc239c/attachment.html <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160315/8afc239c/attachment.html>>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> yt-users mailing list
> yt-users@lists.spacepope.org <mailto:yt-users@lists.spacepope.org>
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org <http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org>
>
>
> ------------------------------
>
> End of yt-users Digest, Vol 97, Issue 19
> ****************************************
>
>
>
> --
> SK2
>
> "Claiming that something can move faster than light is a good conversation-stopper in physics. People edge away from you in cocktail parties; friends never return phone calls. You just don?t mess with Albert Einstein."
>
> _______________________________________________
> yt-users mailing list
> yt-users@lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160316/76eb7890/attachment.htm>

------------------------------

Subject: Digest Footer

_______________________________________________
yt-users mailing list
yt-users@lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org


------------------------------

End of yt-users Digest, Vol 97, Issue 20
****************************************



--
SK2

"Claiming that something can move faster than light is a good conversation-stopper in physics. People edge away from you in cocktail parties; friends never return phone calls. You just don’t mess with Albert Einstein."

_______________________________________________
yt-users mailing list
yt-users@lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org