1

I cannot get the graph to print using the code below. I tried multiple variations of plt.show() and nothing prints to the console, updated to include all of the code

import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
%matplotlib inline
import pandas as pd
import numpy as np
import seaborn as sns

#!curl -o marathon-data.csv https://raw.githubusercontent.com/jakevdp/marathon-data/master/marathon-data.csv?accessType=DOWNLOAD
data = pd.read_csv('marathon-data.csv')
data.head()

# by default pandas loaded the time columns as strings
data.dtypes
data['fina']=pd.to_datetime(data['final'])

data['split_delta']=pd.to_timedelta(data.split, errors='coerce')
data['final_delta']=pd.to_timedelta(data.final, errors='coerce')

data['split_seconds'] = data['split_delta'].dt.total_seconds()
data['split_final'] = data['final_delta'].dt.total_seconds()

data['final_sec']=data['split_final'].astype(int) / 1E9
data['split_sec']=data['split_seconds'].astype(int) / 1E9


with sns.axes_style('white'):
    g = sns.jointplot(x='split_sec', y='final_sec', data=data, kind='hex')
    g.ax_joint.plot(np.linspace(4000, 16000),
                    np.linspace(8000, 32000), ':k')
plt.show()
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
johnsmith_228
  • 105
  • 3
  • 11
  • This is not [reproducible](https://stackoverflow.com/help/minimal-reproducible-example) as-is, since `data` is not defined. Also, I'm guessing from `%matplotlib inline` that you're running this in Jupyter Notebook, is that correct? – CrazyChucky Jan 02 '21 at 22:53
  • try doing `plt.ion()` or `g.show()` or `plt.show(g)` or `plt.show(sns)` maybe? not familiar with what sns returns as `g` but you're definitely calling show on the wrong object...more info here https://stackoverflow.com/questions/26597116/seaborn-plots-not-showing-up – Derek Eden Jan 02 '21 at 23:12
  • maybe bad assumption but didnt think the underlying data would matter, added the full code now – johnsmith_228 Jan 02 '21 at 23:16
  • Also running in Spyder – johnsmith_228 Jan 02 '21 at 23:29
  • Have you tried to run it from a shell? You should remove '%matplotlib inline' and turn 'import matplotlib.pyplot as plt' into 'import pylab as plt'. Maybe some error is raised... – PieCot Jan 02 '21 at 23:57
  • 1
    By default Spyder shows the plots in the plot section. Probably you're getting your plots, and you can see them with `Ctrl+Shift+G` or View > Panes > Plots. Also, `%matplotlib inline` doesn't work in recent versions of Spyder. Finally, select the "plots" tab. – Cainã Max Couto-Silva Jan 03 '21 at 00:08
  • 1
    Cainã Max Couto-Silva, thats it! I just updated Spyder and was used to running all the graphs through the console vs plots. Thanks – johnsmith_228 Jan 03 '21 at 00:10

1 Answers1

1

By default Spyder shows the plots in the plot section. Probably you're getting your plots, and you can see them with Ctrl+Shift+G or View > Panes > Plots. Also, %matplotlib inline doesn't work in recent versions of Spyder. Finally, select the "plots" tab. – Cainã Max Couto-Silva 2 mins ago

This comment answered the question.

johnsmith_228
  • 105
  • 3
  • 11