Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8793549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:08:10+00:00 2026-06-13T23:08:10+00:00

Im attempting to plot some data with matplotlib and i need some of the

  • 0

Im attempting to plot some data with matplotlib and i need some of the annotate to be formated like math/chem formulas.
here is some of my code.

#!/usr/bin/python2 
import numpy as np
import matplotlib.pyplot as pytl
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)
recdt = np.dtype([('compound',str,4),('H_v','f4'),('B_o','f4')]);
gat =  np.loadtxt('tra',dtype=object, usecols=(0,1,2),unpack=True);
gct,ght,gbt=[],[],[]
for c,h,b in np.transpose(gat):
    gct=np.append(gct,c)
    ght=np.append(ght,h)
    gbt=np.append(gbt,b)
ght= ght.astype(np.float)
gbt= gbt.astype(np.float)
hard = pytl
four = hard   #####  
four.scatter(gbt,ght)
hard.title( 'physical stuff' )
hard.xlabel('physical prop 1')
hard.ylabel('physical prop2 ')
for l,x1,y2 in zip ( gct,gbt,ght):
    hard.annotate( l,xy=(x1,y2),xytext=(-24,12),textcoords = 'offset points', arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'),rotation=0 )
hard.ylim([0,10])
hard.savefig('hardcomp.png')
hard.show()

and here is some test data

ZrC 6.8 1
NbC 8   2
NbN 7   13
RuB2    30  5
BP  3   1
AlP 9.4 3
InSb    2.2 47
C   6   4

the data is in three columns one text the other two are numbers.
i’d like the ‘2’ in ‘RbB2’ to end up as a subscript.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:08:11+00:00Added an answer on June 13, 2026 at 11:08 pm

    We can display the 2 in 'RbB2' with a subscript, by using TeX notation: $\tt{RbB_{2}}$. In the code, you just have to modify c:

    import re
    for c,h,b in np.transpose(gat):
        c = r'$\tt{{{c}}}$'.format(c = re.sub(r'(\d+)',r'_{\1}', c))
    

    which yields

    enter image description here


    import re
    import numpy as np
    import matplotlib.pyplot as pytl
    from matplotlib import rc
    
    rc('font', **{'family':'sans-serif', 'sans-serif':['Helvetica']})
    rc('text', usetex = True)
    recdt = np.dtype([('compound', str, 4), ('H_v', 'f4'), ('B_o', 'f4')]);
    gat =  np.loadtxt('tra', dtype = object, usecols = (0, 1, 2), unpack = True);
    gct, ght, gbt = [], [], []
    for c, h, b in np.transpose(gat):
        c = r'$\tt{{{c}}}$'.format(c = re.sub(r'(\d+)', r'_{\1}', c))
        gct = np.append(gct, c)
        ght = np.append(ght, h)
        gbt = np.append(gbt, b)
    ght = ght.astype(np.float)
    gbt = gbt.astype(np.float)
    hard = pytl
    four = hard   #####  
    four.scatter(gbt, ght)
    hard.title( 'physical stuff' )
    hard.xlabel('physical prop 1')
    hard.ylabel('physical prop2 ')
    for l, x1, y2 in zip ( gct, gbt, ght):
        print(l, x1, y2)
        hard.annotate(
            l, xy = (x1, y2), xytext = (-24, 12), textcoords = 'offset points',
            arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'),
            rotation = 0 )
    hard.ylim([0, 10])
    hard.savefig('hardcomp.png')
    hard.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to create a scatter plot bounded by histograms of the data to
Possible Duplicate: How to plot data against specific dates on the x-axis using matplotlib
Attempting to parse json from a url requiring login. Including all my code here
I'm using ggplot2 and attempting to create an empty plot with some basic dimensions,
I'm attempting to script a contour polar plot in R from interpolated point data.
Attempting to use the data series from this example no longer passes the JSONLint
I'm attempting to use ggplot2 and maps to plot the names of the counties
I am working on a bit of javascript to plot data on a <canvas
I have table of data that I am attempting to use lattice in R
Attempting to compile the following code under Qt SDK 4.7.4 for Desktop - MinGW

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.