my pandas and seaborn comands not responding - python

import pandas as pd
dataFrame = pd.read_excel("C:/Users/****/desktop/python folder/tensorflow/sheet.xlsx")
import seaborn as sbn
import matplotlib.pyplot as plt
sbn.pairplot(dataFrame)
Output is: PS C:\Users \ -----\Desktop\python folder> & C:/Users/------/AppData/Local/Programs/Python/Python39/python.exe "c:/Users/-----/Desktop/python folder/tensorflow/tensorflow-101.py"

For your problem, try this.
import seaborn as sbn
import matplotlib.pyplot as plt
sbn.pairplot(dataFrame)
plt.show()
Graph will appear in new window, I guess. It's why your code is working in jupyter, and not in script.
ps. vsc is just a editor, so you can't use vsc for executing python. You are executing python script with your own python program.

Related

Python - percentage symbol on imports

I'm following this tutorial and I've tried to copy the code of the first example.
this is the first lines on the example:
from PIL import Image
import random
import time
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow, show
import matplotlib.animation as animation
#this is crucial to animation in matplotlib
%matplotlib notebook
.
.
.
As you can see, right underneath the imports, there is this line %matplotlib notebook. this line is causing a problems because it doesn't recognized as a command.
this is the problem description: Statement expected, found Py:PERC and End of statement expected
My question is - what is the meaning of the percentage symbol in this case and why doesn't it work?
This syntax is a Jupyter notebook convention. If you are not using Jupyter notebook, then you can probably remove this line.

OSMNX - trying to plot graph in console without any luck

I have the following code
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point, LineString
import matplotlib.pyplot as plt
import networkx as nx
import osmnx as ox
ox.config(use_cache=True, log_console=True)
G = ox.graph_from_point((37.79, -122.41), dist=750, network_type='all')
ox.plot_graph(G)
plt.show()
I am simply trying to plot a simple figure in the console, but there is no output at all. The above code is written in a script. Anyone that knows what the issue is?
Platform: Spyder (Python 3.8)
I fixed the issue. To make the plots appear in the Console, I had to uncheck "Mute Inline Plotting" under Plots pane options menu.

jupyter notebook won't show images

#%%
from Utils.ConfigProvider import ConfigProvider
import os
import cv2
import numpy as np
from matplotlib import pyplot as plt
config = ConfigProvider.config()
and
#%%
inspected = cv2.imread(config.data.inspected_image_path, 0)
reference = cv2.imread(config.data.reference_image_path, 0)
diff = np.abs(inspected - reference)
plt.figure()
plt.title('inspected')
plt.imshow(inspected)
plt.show()
note config.data.inspected_image_path and config.data.reference_image_path are valid paths.
No errors appear, but no images are shown as well.
Running the same code from a python file does show the image.
I have something missing from the notebook.
This happens both when running using jupyter notebook and directly from PyCharm (pro)
How do I get to see images? all other answers I found just tell me to plt.show() but this obviously does not work.
I don't mind a cv2 solution as well.
You need to set a matplotlib backend.
You can do this with
%matplotlib inline
If you want to be able to interact with the plot, use
%matplotlib notebook

Figure not displayed with matplotlib.use('Agg')

I work with matplotlib. When I add the following lines, the figure is not displayed.
import matplotlib
matplotlib.use('Agg')
here is my code :
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plot
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
fig = plot.figure(figsize=(12,9))
def convert_sin_cos(x):
fft_axes = fig.add_subplot(331)
y = np.cos(x)
fft_axes.plot(x,y,'g*')
for i in range(3):
fft_axes = fig.add_subplot(332)
x=np.linspace(0,10,100)
fft_axes.plot(x,i*np.sin(x),'r+')
plot.pause(0.1)
convert_sin_cos(x)
Thanks
That's the idea!
When I run your code, the console says:
matplotlibAgg.py:15: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
How can it be useful? When you're running matplotlib code in a terminal with no windowing system, for example: a cluster (running the same code with different inputs, getting lot of results and without the need to move the data I can plot whatever I need).

plt.show() not executing properly

Currently, I am attempting to follow along with a Sentdex YouTube tutorial video (https://www.youtube.com/watchv=cExOVprMlQg&list=PLQVvvaa0QuDe6ZBtkCNWNUbdaBo2vA4RO), however I am running into some difficulties with plt.show(). I have written this script nearly verbatim as detailed in this video and I have turned to StackOverflow to update any syntax, yet I have not been able to actually view this graph. Nothing comes up when I run the script, the shell just spits out '>>'. I have changed backends, unistalled, upgraded and reinstalled matplotlib. I've also tried this script on the exact version of Python seen in this video as well as 3.6.1 and a few others on OS X and Windows 10 via Parallels - still running into the same issue.
Here is my code thus far:
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np
import pylab
def graphRawFX():
date, bid, ask = np.loadtext('GBPUSD1d.txt', unpack=True,
delimiter='-',
converters={0: mdates.strpdate2numb('%Y%m%d%H%M%S')})
fig = plt.figure(figsize=(10,7))
ax1 = plt.subplot2grid((40,40), (0), rowspan=40, colspan=40)
ax1.plot(date, bid)
ax1.plot(date, ask)
ax1.xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d %H:#M:#S'))
for label in ax1.axis,get_xticklabels():
label.set_rotation(45)
ply.gca().get_yaxis().get_major_formatter().set_useOffset(False)
plt.grid(True)
plt.show()
pylab.show()
Any thoughts on a solution?
You defined a function, which plots. But you never call the function! Your script is empty from python's perspective.
Add graphRawFX() at the end, without any indentation to actually call the function.
If this code is by any means incomplete and not your issue, check your install and clean up the code. The whole import pylab thing looks unwanted. Also ply does not exist and so on. Start with the basics, the official examples and the docs, not with some yt-video which uses tons of (advanced) stuff.
I have it working (mac OS). Just try to copy paste to see if there's some typing problem. (it was working without "import pylab" and the "pylab.show()" I have just put it to have the same code you have.
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticher
import matplotlib.dates as mdates
import numpy as np
import pylab
def graphRawFX():
date,bid,ask = np.loadtxt('GBPUSD1d.txt', unpack=True, delimiter=',',converters={0:mdates.strpdate2num('%Y%m%d%H%M%S')})
fig = plt.figure(figsize=(10,7))
ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
ax1.plot(date,bid)
ax1.plot(date,ask)
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
for label in ax1.xaxis.get_ticklabels() :
label.set_rotation(45)
ax1_2=ax1.twinx()
ax1_2.fill_between(date,0, (ask-bid),facecolor='g',alpha=.3)
plt.subplots_adjust(bottom=.23)
plt.grid(True)
plt.show()
pylab.show()
graphRawFX()

Categories

Resources