wiheto / netplotbrain

A package to create simple 3D network visualizations on a brain.
Apache License 2.0
67 stars 7 forks source link

Error when using self-defined axes #65

Closed LeiGuo0812 closed 11 months ago

LeiGuo0812 commented 11 months ago

Hi!

I'm trying to plot multiple plots in a figure, but I encounted an error when I try to pass the parameter ax. Here below is a example:

import netplotbrain
import pandas as pd
import matplotlib.pyplot as plt

import netplotbrain
import pandas as pd

# Define the nodes
nodes_df = pd.DataFrame({'x': [40, 10, 30, -15, -25], 
                         'y': [50, 40, -10, -20, 20], 
                         'z': [20, 30, -10, -15, 30]})
# Call netplotbrain to plot

fig, ax = plt.subplots(1,1,figsize=(5,5))
netplotbrain.plot(ax = ax, nodes=nodes_df, arrowaxis=None)

The error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File [d:\Softwares\Mambaforge\envs\gl\Lib\site-packages\netplotbrain\plot.py:200](file:///D:/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py:200), in plot(nodes, fig, ax, view, edge_weights, frames, edges, template, network, edge_color, node_size, node_color, node_type, hemisphere, highlight_nodes, highlight_edges, **kwargs)
    [198](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=197) affine = None
    [199](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=198) if template is not None and viewtype[fi]=='b':
--> [200](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=199)     affine = _plot_template(ax, template_style_frame, template,
    [201](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=200)                             hemisphere=hemi_frame,
    [202](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=201)                             azim=azim[fi], elev=elev[fi],
    [203](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=202)                             **profile)
    [205](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=204) # Template voxels will have origin at 0,0,0
    [206](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=205) # It is easier to scale the nodes from the image affine
    [207](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=206) # Then to rescale the ax.voxels function
    [208](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=207) # So if affine is not None, nodes get scaled in relation to origin and voxelsize,
    [209](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=208) # If node coords are derived from nodeimg, this has already been taken care of.
    [210](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/netplotbrain/plot.py?line=209) if nodes is not None and nodeimg is None and viewtype[fi]=='b' and scaled_nodes == False:
...
   [1448](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/matplotlib/__init__.py?line=1447)     bound = new_sig.bind(ax, *args, **kwargs)
   [1449](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/matplotlib/__init__.py?line=1448)     auto_label = (bound.arguments.get(label_namer)
   [1450](file:///d%3A/Softwares/Mambaforge/envs/gl/Lib/site-packages/matplotlib/__init__.py?line=1449)                   or bound.kwargs.get(label_namer))

TypeError: Axes.scatter() got multiple values for argument 's'

I'm not sure if I am doing it wrong. Thanks a lot!

wiheto commented 11 months ago

Hi,

I think the problem is that you are not using 3D axis from matplotlib

fig  = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111, projection='3d')

Adding the projection='3d' to the axis is the critical bit.

This should solve the problem.

LeiGuo0812 commented 11 months ago

It worked! Thanks a lot!