Python hist plot truncates subsequent Python chunk output, if run chunks, but works OK if knit

I run RStudio and reticulate (latest versions) on a windows 10 machine

When I step through my .Rmd file by running one chunk at a time, and I run a Python chunk that creates a hist of a series that contains categorical data, I get the bar chart, but after that all the output of subsequent Python chunks gets truncated: I get exactly one line of output (in a R Console panel) after each Python chunk.

The same happens if I “Run all” chunks

If I knit exactly the same .Rmd file, all the output (the histogram and the output of subsequent Python chunks) gets produced normally.

If I comment out that particular histogram chunk, then stepping through the .Rmd file by running one chunk at a time or by running all chunks also works fine.



print("\n start with import_python_packages")

from sklearn.model_selection import train_test_split

from sklearn.model_selection import StratifiedShuffleSplit

import os
print("print (done import os) do os.getcwd()")
print(os.getcwd() )

os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/Users/userXYZ/AppData/Local/r-miniconda/envs/r-reticulate/Library/plugins/platforms'

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

print("\n done with import_python_packages")

A bunch of Python and R chunks that work fine.

bins=[0., 1.5, 3.0, 4.5, 6., np.inf],
labels=[1, 2, 3, 4, 5])

print("type(temp_cat)",type(temp_cat), "\n")
type(temp_cat) <class 'pandas.core.series.Series'> 
{python median_income_cat_histogram}

temp_cat.hist(figsize=(20,15), color="blue")
# # save_fig("attribute_histogram_plots_median_income_blue")

Run this Python chunk and get a bar chart of the temp_cat

After that every Python chunk that I run that is supposed to print output prints exactly one line of output (and puts it into an R console box, rather than simply in the output field.

If I run exactly the same .Rmd through knit, the output looks fine.

It is possible that this problem is related to this issue: maptlotlib plot causes knitting of .Rmd to get stuck

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.