问题
I may have created a duplicate, but could not find exactly what I was looking for in any thread. I created graphics using OriginPro 8.5G and can not quite re-create them using matplotlib. I am quite new to styling graphics using mpl, but I will attach, what I have already tried and show some pictures.
Plot created using OriginPro 8.5G
Plot created using matplotlib.pyplot
The code used is as follows:
import matplotlib as mpl
from matplotlib import rcParams, cycler
import matplotlib.pyplot as plt
from matplotlib.pyplot import plot, show
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Arial', 'Helvetica', 'Verdana', 'DejaVu Sans']
rcParams['font.size'] = 15
rcParams['axes.linewidth'] = 1.1
rcParams['axes.labelpad'] = 5.0
plot_color_cycle = cycler('color', ['000000', '0000FE', 'FE0000', '008001', 'FD8000', '8c564b', 'e377c2', '7f7f7f', 'bcbd22', '17becf'])
rcParams['axes.prop_cycle'] = plot_color_cycle
rcParams['axes.xmargin'] = 0
rcParams['axes.ymargin'] = 0
for ion in range(1, output_array_size_x):
plt.scatter(output_array[:,0], output_array[:,ion], marker='D')
plt.ylabel('Normalized signal intensity')
plt.xlabel('Excitation voltage [eV]')
plt.show()
Where output_array_size_x
is variable with my input files, but in this case it is 3
.
What I want to do concretely:
I would like the marker to be non-filled and see-through, as in the example of the Origin graphic
The margins/ paddings should ideally be the same as in the Origin graphic
y- and x-axis should begin at exactly 0.0 and not slightly above
The output_array looks like this:
0.000000000000000000e+00 9.613190459262268561e-01 3.513449460836592236e-02 3.546459465407208068e-03
1.500000000000000000e+00 9.344751080827480294e-01 6.157866582480509693e-02 3.946226092446923107e-03
3.000000000000000000e+00 8.794867691496672801e-01 1.158346590855604402e-01 4.678571764772331693e-03
4.500000000000000000e+00 7.778204354741402593e-01 2.161575165907969054e-01 6.022047935062798014e-03
6.000000000000000000e+00 6.237757882444531221e-01 3.677228493577267554e-01 8.501362397820164118e-03
7.500000000000000000e+00 4.352079352079352148e-01 5.524160524160524055e-01 1.237601237601237622e-02
9.000000000000000000e+00 3.037328226321271418e-01 6.814501226354869878e-01 1.481705473238584779e-02
1.050000000000000000e+01 1.979494349295118361e-01 7.804380752650588171e-01 2.161248980542933643e-02
1.200000000000000000e+01 1.991559485530546569e-01 7.682877813504823683e-01 3.255627009646302333e-02
1.300000000000000000e+01 2.117732033224991040e-01 7.502347417840375954e-01 3.799205489346334230e-02
1.200000000000000000e+01 1.737333926641662918e-01 7.915580700527620195e-01 3.470853728307164016e-02
1.050000000000000000e+01 2.083233790434325661e-01 7.730899708538391257e-01 1.858665010272827350e-02
9.000000000000000000e+00 2.918319459187664333e-01 6.940052516900385715e-01 1.416280239119503855e-02
7.500000000000000000e+00 4.381243063263041138e-01 5.503408910734104431e-01 1.153480260028539803e-02
6.000000000000000000e+00 6.196725291324989282e-01 3.727206517047906842e-01 7.606819162710401483e-03
4.500000000000000000e+00 7.784601309988418150e-01 2.166833740474359837e-01 4.856494953722177016e-03
3.000000000000000000e+00 8.823418723003891850e-01 1.136723260488388954e-01 3.985801650771928287e-03
1.500000000000000000e+00 9.367085677246105302e-01 6.041314597464329805e-02 2.878286300746193873e-03
0.000000000000000000e+00 9.603569624515911896e-01 3.714430038727058181e-02 2.498737161138238610e-03
If any further information is required, let me know! Help would greatly be appreciated.
回答1:
I think the following is roughly the equivalent to the Origin figure.
Unfortunately, not everything can be determined via rcParams, such as the limits and the minor tick locations. Also I changed scatter
to plot
, which makes it easier to get hollow markers.
from matplotlib import rcParams, cycler
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Arial']
rcParams['font.size'] = 16
rcParams['axes.linewidth'] = 1.1
rcParams['axes.labelpad'] = 10.0
plot_color_cycle = cycler('color', ['000000', '0000FE', 'FE0000', '008001', 'FD8000', '8c564b',
'e377c2', '7f7f7f', 'bcbd22', '17becf'])
rcParams['axes.prop_cycle'] = plot_color_cycle
rcParams['axes.xmargin'] = 0
rcParams['axes.ymargin'] = 0
rcParams.update({"figure.figsize" : (6.4,4.8),
"figure.subplot.left" : 0.177, "figure.subplot.right" : 0.946,
"figure.subplot.bottom" : 0.156, "figure.subplot.top" : 0.965,
"axes.autolimit_mode" : "round_numbers",
"xtick.major.size" : 7,
"xtick.minor.size" : 3.5,
"xtick.major.width" : 1.1,
"xtick.minor.width" : 1.1,
"xtick.major.pad" : 5,
"xtick.minor.visible" : True,
"ytick.major.size" : 7,
"ytick.minor.size" : 3.5,
"ytick.major.width" : 1.1,
"ytick.minor.width" : 1.1,
"ytick.major.pad" : 5,
"ytick.minor.visible" : True,
"lines.markersize" : 10,
"lines.markerfacecolor" : "none",
"lines.markeredgewidth" : 0.8})
for ion in range(1, output_array_size_x):
plt.plot(output_array[:,0], output_array[:,ion], marker='D', ls="none")
plt.xlim(0, 13)
plt.ylim(0, None)
plt.ylabel('Normalized signal intensity')
plt.xlabel('Excitation voltage [eV]')
plt.gca().xaxis.set_minor_locator(AutoMinorLocator(n=2))
plt.gca().yaxis.set_minor_locator(AutoMinorLocator(n=2))
plt.savefig("out.png", dpi=1000)
plt.show()
来源:https://stackoverflow.com/questions/59222659/making-pythons-matplotlib-graphics-look-like-graphics-created-using-originpro