Circular Graph Resolution

I am working on some charts using the plot_connectivity_circle command. It’s going well, but the outputs it produces seem to be a pretty low resolution (About 72 pixels/inch - when I need 300 pixels/inch). I would like to know if there is a good way of increasing the resolution of the output.

My question seems to align with this older forum question that, unfortunately, went unanswered.

The function mne_connectivity.viz.plot_connectivity_circle() accepts an ax argument where you can pass in a Matplotlib Polar Axes instance to plot into. You can use Matplotlib’s capabilities to pre-size the figure and axes to whatever size you want. In addition, the function returns a reference to the figure and axes that were plotted into, so even if you let the function create the figure/axes for you instead of providing a pre-made axes to ax, you can still use Matplotlib’s capabilities to resize the figure/axes to your liking after the plot is made (e.g., fig.set_size_inches()).

1 Like

Thank you for the reply!

So a couple follow up questions:

-Does this argument or any other argument accept a dpi as an input? As the other poster mentioned, I’d like to get a dpi of 300 for publication purposes.

-Given the below chunk of the script, where does the command in your example belong? In the parenthesis of the plot_connectivity_circle command as an argument, or before/after it such as the way they use the “ax” argument at the end of this example?

-How does this behave when I am requesting 4 different charts simultaneously (As shown).

Here is (what I believe to be) the relevant chunk of my script:

plot_connectivity_circle(ARRAY1, label_names, n_lines=100, node_angles=node_angles, title="Theta", vmax=1.0, colorbar_size=0.25, fontsize_title=22, fontsize_names=16, fontsize_colorbar=8, facecolor="w", textcolor="k", colormap=cmaptheta, vmin=-1.0, node_colors="w", node_edgecolor="k" )
plot_connectivity_circle(ARRAY2, label_names, n_lines=100, node_angles=node_angles, title="Beta", vmax=1.0, colorbar_size=0.25, fontsize_title=22, fontsize_names=16, fontsize_colorbar=8, facecolor="w", textcolor="k", colormap=cmapbeta, vmin=-1.0, node_colors="w", node_edgecolor="k" )
plot_connectivity_circle(ARRAY3, label_names, n_lines=100, node_angles=node_angles, title="Low Gamma", vmax=1.0, colorbar_size=0.25, fontsize_title=22, fontsize_names=16, fontsize_colorbar=8, facecolor="w", textcolor="k", colormap=cmaplowgamma, vmin=-1.0, node_colors="w", node_edgecolor="k" )
plot_connectivity_circle(ARRAY4, label_names, n_lines=100, node_angles=node_angles, title="High Gamma", vmax=1.0, colorbar_size=0.25, fontsize_title=22, fontsize_names=16, fontsize_colorbar=8, facecolor="w", textcolor="k", colormap=cmaphighgamma, vmin=-1.0, node_colors="w", node_edgecolor="k" )

Also sorry to ask so much! I’m trying to brute force anything I can on my own and experiment with it. But I have almost no prior experience with python or matplotlib so things like

where you can pass in a Matplotlib Polar Axes instance to plot into.

Are like a foreign language to me still. In particular, I understand the basic command + argument format:

command(argument1, argument2,...)

but I’ve had a hard time understanding the repeated use of these 3 formats:

fig.something
fig, axes
for ax, something

So given the fragment

fig.set_size_inches()

I am not sure what is an object that I have to define, what is a pre-defined command, and where/how it connects to/interacts with the code for my charts

Maybe if I understood the syntax happening here I’d be able to reverse engineer solutions a little better? I am somewhat familiar with data types and parts of code (command, parameter, object, string, float, integer, dict, list) but this change of format/context makes it a little harder to identify a piece of code I’ve never seen before. It seems like at least one of these requires an object be declared prior, and then does some sort of command with, within, or in relation to the object. The circular graph example I linked earlier has in-code links to some helpful descriptions, but lacks others. I’m not sure if any of that helps indicate what would be a good answer to the question, but I appreciate the time and the help either way! I have nonetheless pulled up some matplotlib documentation to glaze over in the meantime.

allow me to rewrite this a bit, to make it clearer what is the same across all plots and what is different in each plot:

common_params = dict(n_lines=100, node_angles=node_angles, vmax=1.0, colorbar_size=0.25,
                     fontsize_title=22, fontsize_names=16, fontsize_colorbar=8,
                     facecolor="w", textcolor="k", vmin=-1.0, node_colors="w",
                     node_edgecolor="k")

plot_connectivity_circle(ARRAY1, label_names, title="Theta", colormap=cmaptheta, **common_params)
plot_connectivity_circle(ARRAY2, label_names, title="Beta", colormap=cmapbeta, **common_params)
plot_connectivity_circle(ARRAY3, label_names, title="Low Gamma", colormap=cmaplowgamma, **common_params)
plot_connectivity_circle(ARRAY4, label_names, title="High Gamma", colormap=cmaphighgamma, **common_params)

Next, let’s change it to keep track of the output value of each plot function:

fig1, ax1 = plot_connectivity_circle(ARRAY1, label_names, title="Theta", colormap=cmaptheta, **common_params)
fig2, ax2 = plot_connectivity_circle(ARRAY2, label_names, title="Beta", colormap=cmapbeta, **common_params)
fig3, ax3 = plot_connectivity_circle(ARRAY3, label_names, title="Low Gamma", colormap=cmaplowgamma, **common_params)
fig4, ax4 = plot_connectivity_circle(ARRAY4, label_names, title="High Gamma", colormap=cmaphighgamma, **common_params)

now each figure fig1, fig2, is a Matplotlib Figure object, which has its own methods, so we can do things like

fig1.set_size_inches(18, 18)
fig1.set_dpi(300)
fig1.savefig('theta.tif') # or jpg, pdf, svg, png... there are many format options
2 Likes