garrettj403 / SciencePlots

Matplotlib styles for scientific plotting
MIT License
6.96k stars 700 forks source link

[Help Request]: I am only getting ticks on the right and top of my plots, also the colors of the lines are odd #105

Closed tomasrojasc closed 10 months ago

tomasrojasc commented 10 months ago

Environment

System: Linux-6.5.8-arch1-1-x86_64-with-glibc2.38
Python: 3.10.11 | packaged by conda-forge | (main, May 10 2023, 18:58:44) [GCC 11.3.0]
SciencePlots: 2.1.0
Matplotlib: 3.7.1
Latex distro: TeX Live 2023/Arch Linux

Describe your issue here

When I use any style of this package I do not get figures line in the README. I get similar figures but the ticks are only inside the plot in the right side and the top side, in the left and bottom there is no ticks at all. Also the default colors of matplotlib seem to be overwritten for another palette.

How can we reproduce it? What have you tried?

import matplotlib.pyplot as plt
import scienceplots
plt.style.use('science')
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)
y2 = np.cos(x)
plt.plot(x, y)
plt.plot(x, y2)

When I run this on a jupyter notebook, the output is a shown in the figure attached https://imgur.com/a/xFvZ5hD

Extra info

No response

echedey-ls commented 10 months ago

I can´t reproduce, on Google Colab nor in VS Code. Can you provide your code editor? And do you mind double checking the output on a whole new and clean project/notebook?

It only comes to my mind that your environment sets matplotlib to use a style that by default. Btw, try updating matplotlib and the ipython kernels.

EDIT: can you show the output without any styles applied?

tomasrojasc commented 10 months ago

Hi, yes something is odd, without any styles I get this: https://imgur.com/a/Wpfwvq6

Which seems the default seaborn template... although I haven't even imported seaborn.

EDIT: I am using kedro as framework and pycharm as editor

echedey-ls commented 10 months ago

Two things:

  1. You can call mpl.rcParams or plt.rcParams and that will throw the dictionary with all config from the applied styles. Unluckily matplotlib does not save your current styles. Call that from a terminal and from inside PyCharm without making use of plt.style.use(...). That way you can compare both and tell if PyCharm is introducing its styles by default. You may want to use an script to compare those dictionaries. And if you think seaborn matches that, import it with the use statement and check.
  2. You can set default values for rcParams with:
    import matplotlib as mpl
    mpl.rcParams.update(mpl.rcParamsDefault)

    (reference)

If you find something or this works, pls, let us know!

tomasrojasc commented 10 months ago

Apparently PyCharm does introduce an style, I have it almost working, what I done is I first set the default config of matplotlib, then the science style, and now I get this: https://imgur.com/a/AwHOcFY

So now I am only missing the colors! Hopefully, although after I have more complex plots that may introduce styles since I heavily rely on seaborn... But one step at a time.

echedey-ls commented 10 months ago

Nice! I'll close this issue since the main problem has been solved.

science style does indeed change the default colors via plt.rcParams['axes.prop_cycle'].

plt.rcParams['axes.prop_cycle'] = plt.rcParamsDefault['axes.prop_cycle']

And see this comment.

tomasrojasc commented 10 months ago

Thank you very much for your help and fast responses!