changing figure properties using plot_bot() in dedalus.extras

242 views
Skip to first unread message

Jack

unread,
May 7, 2021, 4:56:05 PM5/7/21
to Dedalus Users
Hello, 
I adapted the 2d Rayleigh-Benard example code plot_slices.py for my own outputs of a 2D model and got a plot write.png (attached). I also attach the script (dedaplt.py) I used for plotting the sample h5 file data (sample.h5). The script essentially uses the plot-tools in the dedalus.extras module. 

I am wondering if Dedalus allows changes in properties of the figures as in Matplotlib. In particular, I tried to add the following red line in the excerpt code below to make the tick labels larger but it does not work. Also, I am wondering if one can change the font size for the axes titles easily. I tried various things through the method signatures for plot_bot() and plot_bot_3d() but can't make it work. 

So the goal is to change the properties of the tick/colorbar labels and axis titles. 

Any suggestions for the attached code or easy alternative approaches would be appreciated. 


Thanks, 
Jack

with h5py.File(filename, mode='r') as file:
        for index in range(start, start+count):
            for n, task in enumerate(tasks):
                # Build subfigure axes
                i, j = divmod(n, ncols)
                axes = mfig.add_axes(i, j, [0, 0, 1, 1])
                # axes.tick_params(axis='both',labelsize=20)
                # Call 3D plotting helper, slicing in time
                dset = file['tasks'][task]
                plot_tools.plot_bot_3d(dset, 0, index, axes=axes, title=task, even_scale=True)
            # Add time title
            title = title_func(file['scales/sim_time'][index])
            title_height = 1 - 0.5 * mfig.margin.top / mfig.fig.y
            fig.suptitle(title, x=0.48, y=title_height, ha='left')
            # Save figure
            savename = savename_func(file['scales/write_number'][index])
            savepath = output.joinpath(savename)
            fig.savefig(str(savepath), dpi=dpi)
            fig.clear()
    plt.close(fig)
write.png
dedaplt.py
dedaplt.py

Jack

unread,
May 8, 2021, 9:47:38 AM5/8/21
to Dedalus Users
The Google Group keeps saying "Error posting Message". The file sample.h5 mentioned in the previous post cannot be attached. 

Jack

unread,
May 8, 2021, 9:48:51 AM5/8/21
to Dedalus Users
sample.h5.zip

Evan Henry Anders

unread,
May 8, 2021, 10:49:20 AM5/8/21
to dedalus-users
Hi Jack,

dedalus' plot_bot just relies on matplotlib code under the hood, so (I think) all matplotlib function calls should work as intended. Here's another article of various ways to set matplotlib tick labels; it might be worth trying some other methods that aren't tick_params to see if they work? Another option is to try to change your matplotlib parameter configurations (e.g., like here) at the top of your file.

The source code for plot_bot is here: https://github.com/DedalusProject/dedalus/blob/master/dedalus/extras/plot_tools.py. If standard matplotlib function calls aren't working nicely with that code, I'd recommend just making a custom plotting script that produces plots that look the way you want them to look.

Best,
Evan

--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dedalus-users/c3ea5071-c66b-4063-b0a2-7470054a7419n%40googlegroups.com.

Jack

unread,
Jun 4, 2021, 5:41:03 PM6/4/21
to Dedalus Users
Hi Evan, 

Thank you for your suggestions. 

I tried various stuff in the linked article, which seems not working. I find that one can mostly manipulate the figures using the return values of the plot_bot() method:
paxes, caxes = plot_tools.plot_bot(...).  The matplotlib parameter configurations are helpful. 


Best,
Jack
Reply all
Reply to author
Forward
0 new messages