viziphant icon indicating copy to clipboard operation
viziphant copied to clipboard

Bug: viziphant.gpfa plot_trajectories with matplotlib-3.6.2

Open Moritz-Alexander-Kern opened this issue 2 years ago • 1 comments

Tested with:

  • python: 3.8.10
  • viziphant: 0.2.0
  • matplotlib: 3.6.2

The following example:

import numpy as np
import quantities as pq
from elephant.gpfa import GPFA
from elephant.spike_train_generation import StationaryPoissonProcess
from viziphant.gpfa import plot_trajectories
from matplotlib import pyplot as plt

data = []
for trial in range(50):
    n_channels = 20
    firing_rates = np.random.randint(low=1, high=100, size=n_channels) * pq.Hz
    spike_times = [StationaryPoissonProcess(rate=rate).generate_spiketrain()
                   for rate in firing_rates]
    data.append(spike_times)

gpfa = GPFA(bin_size=20*pq.ms, x_dim=8)
gpfa.fit(data)

results = gpfa.transform(data, returned_data=['latent_variable_orth',
                                              'latent_variable'])

trial_id_lists = np.arange(50).reshape(5, 10)
trial_group_names = ['A', 'B', 'C', 'D', 'E']

trial_grouping_dict = {}
for trial_group_name, trial_id_list in zip(trial_group_names, trial_id_lists):
    trial_grouping_dict[trial_group_name] = trial_id_list

plot_trajectories(results,
                  gpfa,
                  dimensions=[0, 1, 2],
                  trial_grouping_dict=trial_grouping_dict,
                  plot_group_averages=True)
plt.show()

gives the following error:

line 572, in plot_trajectories
axes = fig.gca(projection=projection, aspect='auto')
TypeError: gca() got an unexpected keyword argument 'projection'

Moritz-Alexander-Kern avatar Nov 03 '22 17:11 Moritz-Alexander-Kern

This could be traced down to api changes in release 3.6.0 of matplotlib.

The following arguments have been removed:

  • ...
  • Keyword arguments to gca(); there is no replacement.

See also: https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.6.0.html

Moritz-Alexander-Kern avatar Nov 03 '22 17:11 Moritz-Alexander-Kern