plotting a graph in an xml file - matplotlib

I want to show the graph using the python code below, but I am getting a syntax error as seen on the image. Please help to correct this error. I am using Python 3
import os
import sys
import fnss
import networkx as nx
import fnss
import cvxopt
import numpy as np
import codecs
import random
import matplotlib.pyplot as plt
topo_str = 'topo_peter.xml'
topology = fnss.read_topology(topo_str)
topology_directed = topology.to_directed(topology)
print nx.info(topology_directed)
nx.draw(topology_directed)
plt.show()
and this is the am getting
File "<ipython-input-1-fa7157dd7268>", line 14
print nx.info(topology_directed)
^
SyntaxError: invalid syntax

Based on the information provided:
Python version: 3
Error message: invalid syntax on line 14 -> print nx.info(topology_directed)
It is clearly a simple syntax error for people using Python 3 to execute a Python 2 statement.
print "something" # is valid for Python 2, but not Python 3
For Python 3, use
print("something", "and more", "even more")
So changing print nx.info(topology_directed) to print(nx.info(topology_directed)) solves the problem.

Related

VCF file is missing mandatory header line ("#CHROM...")

I am getting an error when I am going to read a VCF file using scikit-allel library inside a docker image and os ubuntu 18.04. It shows that
raise RuntimeError('VCF file is missing mandatory header line ("#CHROM...")')
RuntimeError: VCF file is missing mandatory header line ("#CHROM...")
But in the VCF file is well-formatted.
Here is my code of how I applied :
import pandas as pd
import os
import numpy as np
import allel
import tkinter as tk
from tkinter import filedialog
import matplotlib.pyplot as plt
from scipy.stats import norm
GenomeVariantsInput = allel.read_vcf('quartet_variants_annotated.vcf', samples=['ISDBM322015'],fields=[ 'variants/CHROM', 'variants/ID', 'variants/REF',
'variants/ALT','calldata/GT'])
version what Installed :
Python 3.6.9
Numpy 1.19.5
pandas 1.1.5
scikit-allel 1.3.5
You need to add a line like this in the first:
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT NA00001 NA00002 NA00003
but it's not static for all of the files, you have to make a Header like above for your file. (I suggest try this header first and if it's got error then customize it)

pandas-read-xml has error on 'json-normalize'

I saw there is a way to directly read XML files using pandas. I followed and used this package. However, I keep getting errors.
https://pypi.org/project/pandas-read-xml/
import pandas as pd
import pandas_read_xml as pdx
from pandas.io.json import json_normalize
The error was generated by last line and the error is
ImportError: cannot import name 'json_normalize'
I am using kernel python 3, can anyone tell me what was wrong with it?

Code is running but vs code terminal shows syntax error

import plotly.express as px
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
I imported these libraries and used %matplotlib inline . The code runs fine but the terminal in vs code shows the error :
Syntax Error: invalid syntax
I found an answer to use %matplotlibinline in VS Code
# Suppress matplotlib user warnings
# Necessary for newer version of matplotlib
import warnings
warnings.filterwarnings("ignore", category = UserWarning, module = "matplotlib")
#
# Display inline matplotlib plots with IPython
from IPython import get_ipython
get_ipython().run_line_magic('matplotlib', 'inline')
%matplotlib inline is not a valid python command. This has a specific meaning when used in ipython/jupyter.

Getting an error : "OptionError: 'You can only set the value of existing options'" in python

I am getting an error:
"OptionError: 'You can only set the value of existing options'"
after using the below code, please can someone help?
### Data Analaysis
import numpy as np
import pandas as pd
### Data Visualization
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.graph_objs as go
import plotly.express as px
from plotly.subplots import make_subplots
from scipy.interpolate import make_interp_spline, BSpline
%matplotlib inline
import warnings
warnings.simplefilter(action='ignore', category=Warning)
pd.set_option('display.max_columns', None)
pd.options.plotting.backend = "plotly"
The option error "you can only set the value of existing options" are coming because of your last line of script
pd.options.plotting.backend = "plotly"
where you are trying to update your pandas backend plotting method.
Please update your pandas and plotly packages. Because it only works with pandas version>=0.25 and plotly version>=4.8.
So update both the packages, restart your kernel, if you are working on Jupyter notebook. For upgrading the packages
pip install -U pandas
pip install -U plotly

Can't call matplotlib attributes v3.2.2

Whenever I try to run the following code I get an error message
import matplotlib
import pandas as pd
import _pickle as pickle
import numpy as np
print(matplotlib.version)
AttributeError: module 'matplotlib' has no attribute 'version'
I get the same error if i try this: matplotlib.style.use('bmh')
I'm using PyCharm
The errors are stating those attributes do not exist. It is not a problem of the installation.
To get the version:
print(matplotlib.__version__)
Regarding the style:
You do not "apply" that in matplotlib. You may want to use the module pyplot:
import matplotlib.pyplot as plt
plt.style.use("bmh")