Re: specify line plot color

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: specify line plot color

vincent.adrien@gmail.com
Hi alberto,

If I have correctly understood your wish, you may be looking for in
[numpy.savetxt](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.savetxt.html)
and
[numpy.loadtxt](https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.loadtxt.html).

This may not be really Matplotlib's field anymore, but please find
attached a small example on how to record data into a flat text file and
reload them. Hopefully this will helpful to you.

Best regards,
Adrien

On 06/10/2018 08:30 AM, alberto wrote:

> Hi,
> I wrote days ago about script python
> I would ask you if exist a way to print in a file the data of a plot
>
> this is my script
>
>
> #!/usr/bin/env python
>
>
> import numpy as np
> import matplotlib.pyplot as plt
> import sys
>
> #%%
> # Temperature that we are interested in
> target_T = 10.0
> #%% Load all condtens data
> data = np.loadtxt("Pb8I28-MA-BISIMID_101010Kp_FR.condtens")
> #%% Load trace data
> data2 = np.loadtxt("Pb8I28-MA-BISIMID_101010Kp_FR.trace")
> #print(data[:,1])
> #%%
> # Select only the data points computed at that specific temperature
> T = data[:, 1]
> indices = (T == target_T)
> #print(indices)
>
> #%%Fermi levels converted in electronvolts
> Ef = 13.60 * data[indices, 0]
> print(Ef)
>
>
> #%% plot trace at T
> Fermi_level = 4.44075 # (in eV)
>
> plt.figure()
> labels = ("$\sigma$ / $tau$",)
> for i, label in enumerate(labels):
>      plt.plot((Ef - Fermi_level), data2[indices,(abs(5))], label=label)
> plt.legend(loc="best")
> plt.xlabel(r"Energy-Efermi [eV]")
> plt.ylabel(r"$\sigma$/$\tau$ [$\Omega$ m s]")
> plt.tight_layout()
> plt.show()
>
>
> #%% plot DOS(Ef) at T
>
> au_to_m = 5.291772083E-11
> V = 7670.7134 # a.u.^3
> m_el = 9.10938356E-31 #Kg
> V_m3 = V*(au_to_m)**3
> print(V_m3)
>
> plt.figure()
> labels = ("DOS",)
> for i, label in enumerate(labels):
>      plt.plot(Ef, data2[indices,(3)], label=label)
> plt.legend(loc="best")
> plt.xlabel(r"Ef [eV]")
> plt.ylabel(r"n /($\mu)$ [e / m^3]")
> plt.tight_layout()
> plt.show()
>
>
> #%%
> # And recast as an array of 3x3 matrices for convenience
> # Column numbers are easy to follow: 1 for Ef, 1 for T, 1 for N, 9 for
> sigma,
> # and then comes the Seebeck coefficient
> sigma = data[indices, 3:12].reshape((-1, 3, 3))
> sys.stdout=open('prova.txt','wt')
> print(sigma)
> seebeck = data[indices, 12:21].reshape((-1, 3, 3))
>
> # Plot the xx, yy and zz components as a function of the first column
> plt.figure()
> labels = ("xx", "yy", "zz")
> for i, label in enumerate(labels):
>      plt.plot(Ef, sigma[:, i, i], label=label)
> plt.legend(loc="best")
> plt.xlabel(r"Energy [eV]")
> plt.ylabel(r"$\sigma$ [1/$\Omega$ m s]")
> #plt.axis([4,8,-1,8])
> plt.tight_layout()
> plt.show()
>
>
> in particular I would write four columns with ef and xx yy zz in a
> datafile.txt
>
> regards
>
> Alberto
>
> 2018-04-16 19:22 GMT+02:00 alberto <[hidden email]
> <mailto:[hidden email]>>:
>
>     Hi,
>     thank you so much for your help
>
>     Alberto
>
>     2018-04-16 18:58 GMT+02:00 [hidden email]
>     <mailto:[hidden email]> <[hidden email]
>     <mailto:[hidden email]>>:
>
>         Hi Alberto,
>
>         I now understand better. No need to flip you data then: you can
>         actually explicitly specify the color that  you want in the
>         `plot` function, with the *color* keyword argument. See the
>         attached script that should hopefully help you to get what you want.
>
>         Best regards,
>         Adrien
>
>         On 04/16/2018 09:20 AM, alberto wrote:
>
>             Hi vincet,
>
>             in my plot (see .png file)
>
>             I would invert the color
>
>             xx --> green
>             zz--> blue
>
>
>
>             regards
>
>             Alberto
>
>             ​
>             Pb8I28-MA-PERF-BISIMID_32Kp_101010.condtens
>             <https://drive.google.com/file/d/17YnBjb-8IlL8e_0Kcxj_Y97cJr_adCi4/view?usp=drive_web
>             <https://drive.google.com/file/d/17YnBjb-8IlL8e_0Kcxj_Y97cJr_adCi4/view?usp=drive_web>>
>             ​
>
>
>
>

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

example_alberto.py (1K) Download Attachment
for_alberto.pdf (17K) Download Attachment
datafile.txt (818 bytes) Download Attachment